summaryrefslogtreecommitdiff
path: root/propertysheet/src/org/eclipse/wb/internal/core/model/property/ComplexProperty.java
blob: 69bb455e3eba8a8361547aa1141a288b1d292dfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************************
 * Copyright (c) 2011 Google, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Google, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.wb.internal.core.model.property;

import org.eclipse.wb.internal.core.model.property.editor.TextDisplayPropertyEditor;
import org.eclipse.wb.internal.core.model.property.editor.complex.IComplexPropertyEditor;
import org.eclipse.wb.internal.core.model.property.editor.presentation.PropertyEditorPresentation;
import org.eclipse.wb.internal.core.model.property.table.PropertyTable;
import org.eclipse.wb.internal.core.model.property.table.PropertyTooltipProvider;
import org.eclipse.wb.internal.core.model.property.table.PropertyTooltipTextProvider;

import org.eclipse.swt.graphics.Point;

import java.util.List;

/**
 * Implementation of {@link Property} that shows given inner {@link Property}'s using
 * {@link IComplexPropertyEditor}.
 * 
 * @author scheglov_ke
 * @coverage core.model.property
 */
public class ComplexProperty extends Property {
  private final String m_title;
  private String m_text;
  private String m_tooltip;
  private boolean m_modified;
  private Property[] m_properties;

  ////////////////////////////////////////////////////////////////////////////
  //
  // Constructors
  //
  ////////////////////////////////////////////////////////////////////////////
  public ComplexProperty(String title, String text) {
    this(title, text, new Property[0]);
  }

  public ComplexProperty(String title, String text, Property[] properties) {
    super(new ComplexPropertyEditor());
    m_title = title;
    m_text = text;
    setText(text);
    setProperties(properties);
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Access
  //
  ////////////////////////////////////////////////////////////////////////////
  /**
   * Sets the text.
   */
  public void setText(String text) {
    m_text = text;
  }

  /**
   * @return the text to display as value.
   */
  public String getText() throws Exception {
    return m_text;
  }

  /**
   * Sets the tooltip text.
   */
  public void setTooltip(String tooltip) {
    m_tooltip = tooltip;
  }

  /**
   * Specifies the {@link PropertyEditorPresentation}, for example to displaying "..." button.
   */
  public void setEditorPresentation(PropertyEditorPresentation presentation) {
    ((ComplexPropertyEditor) getEditor()).m_presentation = presentation;
  }

  /**
   * @return the sub-properties.
   */
  public Property[] getProperties() {
    return m_properties;
  }

  /**
   * Sets the sub-properties.
   */
  public void setProperties(Property[] properties) {
    m_properties = properties;
  }

  /**
   * Sets the sub-properties.
   */
  public void setProperties(List<Property> properties) {
    Property[] propertiesArray = properties.toArray(new Property[properties.size()]);
    setProperties(propertiesArray);
  }

  /**
   * Sets the "modified" flag.
   */
  public void setModified(boolean modified) {
    m_modified = modified;
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Property
  //
  ////////////////////////////////////////////////////////////////////////////
  @Override
  public String getTitle() {
    return m_title;
  }

  @Override
  public boolean isModified() throws Exception {
    return m_modified;
  }

  @Override
  public Object getValue() throws Exception {
    return null;
  }

  @Override
  public void setValue(Object value) throws Exception {
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // Adapter
  //
  ////////////////////////////////////////////////////////////////////////////
  @Override
  public <T> T getAdapter(Class<T> adapter) {
    if (adapter == PropertyTooltipProvider.class && m_tooltip != null) {
      return adapter.cast(new PropertyTooltipTextProvider() {
        @Override
        protected String getText(Property property) throws Exception {
          return m_tooltip;
        }
      });
    }
    return super.getAdapter(adapter);
  }

  ////////////////////////////////////////////////////////////////////////////
  //
  // ComplexPropertyEditor
  //
  ////////////////////////////////////////////////////////////////////////////
  private static final class ComplexPropertyEditor extends TextDisplayPropertyEditor
      implements
        IComplexPropertyEditor {
    private PropertyEditorPresentation m_presentation;

    ////////////////////////////////////////////////////////////////////////////
    //
    // IComplexPropertyEditor
    //
    ////////////////////////////////////////////////////////////////////////////
    public Property[] getProperties(Property property) throws Exception {
      return ((ComplexProperty) property).getProperties();
    }

    ////////////////////////////////////////////////////////////////////////////
    //
    // TextDisplayPropertyEditor
    //
    ////////////////////////////////////////////////////////////////////////////
    @Override
    protected String getText(Property property) throws Exception {
      return ((ComplexProperty) property).getText();
    }

    ////////////////////////////////////////////////////////////////////////////
    //
    // PropertyEditor
    //
    ////////////////////////////////////////////////////////////////////////////
    @Override
    public boolean activate(PropertyTable propertyTable, Property property, Point location)
        throws Exception {
      return false;
    }

    ////////////////////////////////////////////////////////////////////////////
    //
    // Presentation
    //
    ////////////////////////////////////////////////////////////////////////////
    @Override
    public PropertyEditorPresentation getPresentation() {
      return m_presentation;
    }
  }
}