CompoundPropertyEditorPresentation.java revision 562c581f49027009d6e99ba7b0162c53a051b1c4
1/*******************************************************************************
2 * Copyright (c) 2011 Google, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *    Google, Inc. - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.wb.internal.core.model.property.editor.presentation;
12
13import com.google.common.collect.Lists;
14
15import org.eclipse.wb.internal.core.model.property.Property;
16import org.eclipse.wb.internal.core.model.property.table.PropertyTable;
17
18import java.util.List;
19
20/**
21 * Implementation of {@link PropertyEditorPresentation} that contains zero or more other
22 * {@link PropertyEditorPresentation}'s.
23 *
24 * @author scheglov_ke
25 * @coverage core.model.property.editor
26 */
27public class CompoundPropertyEditorPresentation extends PropertyEditorPresentation {
28  private final List<PropertyEditorPresentation> m_presentations = Lists.newArrayList();
29
30  ////////////////////////////////////////////////////////////////////////////
31  //
32  // Access
33  //
34  ////////////////////////////////////////////////////////////////////////////
35  /**
36   * Adds child {@link PropertyEditorPresentation}.<br>
37   * Child {@link PropertyEditorPresentation}'s are displayed from right to left.
38   */
39  public void add(PropertyEditorPresentation presentation) {
40    m_presentations.add(presentation);
41  }
42
43  ////////////////////////////////////////////////////////////////////////////
44  //
45  // PropertyEditorPresentation
46  //
47  ////////////////////////////////////////////////////////////////////////////
48  @Override
49  public int show(PropertyTable propertyTable,
50      Property property,
51      int x,
52      int y,
53      int width,
54      int height) {
55    int sumWidth = 0;
56    for (PropertyEditorPresentation presentation : m_presentations) {
57      int presentationWidth = presentation.show(propertyTable, property, x, y, width, height);
58      sumWidth += presentationWidth;
59      width -= presentationWidth;
60    }
61    return sumWidth;
62  }
63
64  @Override
65  public void hide(PropertyTable propertyTable, Property property) {
66    for (PropertyEditorPresentation presentation : m_presentations) {
67      presentation.hide(propertyTable, property);
68    }
69  }
70}
71