Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 38f166ab5de83e684b724c182825f4b968f13243 (plain) (blame)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.properties;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.DialogCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
import org.eclipse.wst.xsd.ui.internal.wizards.RegexWizard;
import org.eclipse.xsd.XSDSchema;
import org.eclipse.xsd.util.XSDConstants;


public class PatternPropertySource
  extends BasePropertySource
  implements IPropertySource
{
  /**
   * 
   */
  public PatternPropertySource()
  {
    super();
//    expressionField.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_PATTERN"));    
//    WorkbenchHelp.setHelp(expressionField, XSDEditorContextIds.XSDE_PATTERN_VALUE);
//    WorkbenchHelp.setHelp(activateWizardButton, XSDEditorContextIds.XSDE_PATTERN_REGULAR);
//    activateWizardButton.setToolTipText(XSDEditorPlugin.getXSDString("_UI_TOOLTIP_REGEX_WIZARD_BUTTON"));
  }
  /**
   * @param viewer
   * @param xsdSchema
   */
  public PatternPropertySource(Viewer viewer, XSDSchema xsdSchema)
  {
    super(viewer, xsdSchema);
  }
  /**
   * @param xsdSchema
   */
  public PatternPropertySource(XSDSchema xsdSchema)
  {
    super(xsdSchema);
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue()
   */
  public Object getEditableValue()
  {
    return null;
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors()
   */
  public IPropertyDescriptor[] getPropertyDescriptors()
  {
    List list = new ArrayList();
    // Create a descriptor and set a category

    PatternTextPropertyDescriptor patternDescriptor =
    new PatternTextPropertyDescriptor(
        XSDConstants.VALUE_ATTRIBUTE, 
        XSDConstants.VALUE_ATTRIBUTE);
    list.add(patternDescriptor);
    
    IPropertyDescriptor[] result = new IPropertyDescriptor[list.size()];
    list.toArray(result);
    return result;
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
   */
  public Object getPropertyValue(Object id)
  {
    Object result = null;
    if (id instanceof String)
    {
      result = element.getAttribute((String) id);
    }
    if (result == null)
    {
      result = "";
    }
    return result;
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object)
   */
  public boolean isPropertySet(Object id)
  {
    return false;
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object)
   */
  public void resetPropertyValue(Object id)
  {
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object)
   */
  public void setPropertyValue(Object id, Object value)
  {
    if (value == null)
    {
      value = "";
    }
    if (value instanceof String)
    {
      if (((String) id).equals(XSDConstants.VALUE_ATTRIBUTE))
      { 
        beginRecording(XSDEditorPlugin.getXSDString("_UI_PATTERN_VALUE_CHANGE"), element);
        element.setAttribute(XSDConstants.VALUE_ATTRIBUTE, (String)value);
        endRecording(element);
      }
    }
    Runnable delayedUpdate = new Runnable()
    {
      public void run()
      {
        if (viewer != null)
          viewer.refresh();
      }
    };
    Display.getCurrent().asyncExec(delayedUpdate);
    
  }

  public class PatternTextPropertyDescriptor extends PropertyDescriptor
  {
    /**
     * @param id
     * @param displayName
     */
    public PatternTextPropertyDescriptor(Object id, String displayName)
    {
      super(id, displayName);
    }
    
    public CellEditor createPropertyEditor(Composite parent)
    {
      // CellEditor editor = new PatternTextCellEditor(parent);
      CellEditor editor = new PatternDialogCellEditor(parent);
      if (getValidator() != null)
        editor.setValidator(getValidator());
      return editor;
    }
  }   

  public class PatternDialogCellEditor extends DialogCellEditor {

    /**
     * Creates a new Font dialog cell editor parented under the given control.
     * The cell editor value is <code>null</code> initially, and has no 
     * validator.
     *
     * @param parent the parent control
     */
    protected PatternDialogCellEditor(Composite parent) {
      super(parent);
    }

    /**
     * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(Control)
     */
    protected Object openDialogBox(Control cellEditorWindow)
    {
      String initialValue = element.getAttribute(XSDConstants.VALUE_ATTRIBUTE);
      if (initialValue == null)
      {
        initialValue = "";
      }
      RegexWizard wizard = new RegexWizard(initialValue);
      Shell shell = Display.getCurrent().getActiveShell();
      WizardDialog wizardDialog = new WizardDialog(shell, wizard);
      wizardDialog.create();
      
      String value = (String)getValue();

      int result = wizardDialog.open();

      if (result == Window.OK)
      {
        return wizard.getPattern();
      }
      return value;
    }

  }
  
//  class PatternTextCellEditor extends OptionsTextCellEditor
//  {
//    protected Button fixedButton, defaultButton;
//    
//    public PatternTextCellEditor(Composite parent)
//    {
//      super(parent);
//    }
//
//    protected Control createControl(Composite parent)
//    {
//      isTextReadOnly = false;
//      return super.createControl(parent);
//    }
//
//    protected void openDialog()
//    {
//      RegexWizard wizard = new RegexWizard(element.getAttribute(XSDConstants.VALUE_ATTRIBUTE));
//      Shell shell = Display.getCurrent().getActiveShell();
//      WizardDialog wizardDialog = new WizardDialog(shell, wizard);
//      wizardDialog.create();
//      
//      dialog = wizardDialog.getShell();
//      Display display = dialog.getDisplay();
//      dialog.addShellListener(new ShellAdapter()
//      {
//        public void shellDeactivated(ShellEvent e)
//        {
//          cancel();
//        }
//      });
//
//      int result = wizardDialog.open();
//
//      if (result == Window.OK)
//      {
//        fText.setText(wizard.getPattern());
//        applyEditorValueAndDeactivate();
//      }
//      
//    }
//
//    protected void cancel()
//    {
//      super.cancel();
//    }
//
//    void applyEditorValueAndDeactivate()
//    {
//      String value = fText.getText();
//      doSetValue(value);
//      fireApplyEditorValue();
//      deactivate();
//    }
//    
//    protected Object doGetValue()
//    { 
//      fValue = fText.getText();
//      return fText.getText();
//    }
//
//  }
}

Back to the top