KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > schema > SchemaElementDetails


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.schema;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.pde.core.IModelChangedEvent;
17 import org.eclipse.pde.internal.core.ischema.IMetaAttribute;
18 import org.eclipse.pde.internal.core.ischema.ISchema;
19 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
20 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
21 import org.eclipse.pde.internal.core.schema.Schema;
22 import org.eclipse.pde.internal.core.schema.SchemaElement;
23 import org.eclipse.pde.internal.core.schema.SchemaElementReference;
24 import org.eclipse.pde.internal.ui.PDEUIMessages;
25 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
26 import org.eclipse.pde.internal.ui.parts.ComboPart;
27 import org.eclipse.pde.internal.ui.parts.FormEntry;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.events.SelectionAdapter;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.graphics.Color;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.ui.forms.IFormColors;
36 import org.eclipse.ui.forms.widgets.FormToolkit;
37
38 public class SchemaElementDetails extends AbstractSchemaDetails {
39
40     private SchemaElement fElement;
41     private FormEntry fName;
42     private ComboPart fLabelProperty;
43     private ComboPart fIcon;
44     private Button fDepTrue;
45     private Button fDepFalse;
46     private Button fTransTrue;
47     private Button fTransFalse;
48     
49     public SchemaElementDetails(ElementSection section) {
50         super(section, true);
51     }
52
53     public void createDetails(Composite parent) {
54         FormToolkit toolkit = getManagedForm().getToolkit();
55         Color foreground = toolkit.getColors().getColor(IFormColors.TITLE);
56         
57         fName = new FormEntry(parent, toolkit, PDEUIMessages.SchemaDetails_name, SWT.NONE);
58         
59         Label label = toolkit.createLabel(parent, PDEUIMessages.SchemaDetails_deprecated);
60         label.setForeground(foreground);
61         Button[] buttons = createTrueFalseButtons(parent, toolkit, 2);
62         fDepTrue = buttons[0];
63         fDepFalse = buttons[1];
64         
65         label = toolkit.createLabel(parent, PDEUIMessages.SchemaElementDetails_labelProperty);
66         label.setForeground(foreground);
67         fLabelProperty = createComboPart(parent, toolkit, new String JavaDoc[0], 2);
68         
69         label = toolkit.createLabel(parent, PDEUIMessages.SchemaElementDetails_icon);
70         label.setForeground(foreground);
71         fIcon = createComboPart(parent, toolkit, new String JavaDoc[0], 2);
72
73         label = toolkit.createLabel(parent, PDEUIMessages.SchemaDetails_translatable);
74         label.setForeground(foreground);
75         buttons = createTrueFalseButtons(parent, toolkit, 2);
76         fTransTrue = buttons[0];
77         fTransFalse = buttons[1];
78         
79         setText(PDEUIMessages.SchemaElementDetails_title);
80     }
81
82     public void updateFields(ISchemaObject object) {
83         if (object instanceof SchemaElementReference)
84             object = ((SchemaElementReference)object).getReferencedObject();
85         fElement = (SchemaElement)object;
86         if (fElement == null)
87             return;
88         setDecription(NLS.bind(PDEUIMessages.SchemaElementDetails_description, fElement.getName()));
89         fName.setValue(fElement.getName(), true);
90         String JavaDoc labProp = fElement.getLabelProperty();
91         fLabelProperty.setItems(getLabelItems());
92         fLabelProperty.setText(labProp != null ? labProp : ""); //$NON-NLS-1$
93
String JavaDoc icProp = fElement.getIconProperty();
94         fIcon.setItems(getIconItems());
95         fIcon.setText(icProp != null ? icProp : ""); //$NON-NLS-1$
96

97         fDepTrue.setSelection(fElement.isDeprecated());
98         fDepFalse.setSelection(!fElement.isDeprecated());
99         
100         fTransTrue.setSelection(fElement.hasTranslatableContent());
101         fTransFalse.setSelection(!fElement.hasTranslatableContent());
102         
103         boolean editable = isEditableElement();
104         fIcon.setEnabled(editable);
105         fLabelProperty.setEnabled(editable);
106         fName.setEditable(editable);
107         
108         fDepTrue.setEnabled(editable);
109         fDepFalse.setEnabled(editable);
110         fTransTrue.setEnabled(editable);
111         fTransFalse.setEnabled(editable);
112     }
113
114     public void hookListeners() {
115         fIcon.addSelectionListener(new SelectionAdapter() {
116             public void widgetSelected(SelectionEvent e) {
117                 if (blockListeners())
118                     return;
119                 String JavaDoc icon = fIcon.getSelection();
120                 if (icon == null || icon.equals("")) //$NON-NLS-1$
121
fElement.setIconProperty(null);
122                 else
123                     fElement.setIconProperty(icon);
124             }
125         });
126         fLabelProperty.addSelectionListener(new SelectionAdapter() {
127             public void widgetSelected(SelectionEvent e) {
128                 if (blockListeners())
129                     return;
130                 String JavaDoc label = fLabelProperty.getSelection();
131                 if (label == null || label.equals("")) //$NON-NLS-1$
132
fElement.setLabelProperty(null);
133                 else
134                     fElement.setLabelProperty(label);
135             }
136         });
137         fName.setFormEntryListener(new FormEntryAdapter(this) {
138             public void textValueChanged(FormEntry entry) {
139                 if (blockListeners())
140                     return;
141                 fElement.setName(fName.getValue());
142                 ((Schema)fElement.getSchema()).updateReferencesFor(fElement, ISchema.REFRESH_RENAME);
143                 setDecription(NLS.bind(PDEUIMessages.SchemaElementDetails_description, fElement.getName()));
144             }
145         });
146         fDepTrue.addSelectionListener(new SelectionAdapter() {
147             public void widgetSelected(SelectionEvent e) {
148                 if (blockListeners())
149                     return;
150                 fElement.setDeprecatedProperty(fDepTrue.getSelection());
151             }
152         });
153         fTransTrue.addSelectionListener(new SelectionAdapter() {
154             public void widgetSelected(SelectionEvent e) {
155                 if (blockListeners())
156                     return;
157                 fElement.setTranslatableProperty(fTransTrue.getSelection());
158             }
159         });
160     }
161     
162     private String JavaDoc[] getIconItems() {
163         ISchemaAttribute[] attribs = fElement.getAttributes();
164         ArrayList JavaDoc list = new ArrayList JavaDoc();
165         list.add(""); //$NON-NLS-1$
166
for (int i = 0; i < attribs.length; i++) {
167             if (attribs[i].getKind() == IMetaAttribute.RESOURCE) {
168                 list.add(attribs[i].getName());
169             }
170         }
171         return (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
172     }
173     
174     private String JavaDoc[] getLabelItems() {
175         ISchemaAttribute[] attribs = fElement.getAttributes();
176         String JavaDoc[] labels = new String JavaDoc[attribs.length + 1];
177         labels[0] = ""; //$NON-NLS-1$
178
for (int i = 0; i < attribs.length; i++) {
179             labels[i + 1] = attribs[i].getName();
180         }
181         return labels;
182     }
183     
184     public void modelChanged(IModelChangedEvent event) {
185         Object JavaDoc[] changedObjs = event.getChangedObjects();
186         if(event.getChangeType() == IModelChangedEvent.INSERT && changedObjs.length > 0) {
187             if (changedObjs[0] instanceof SchemaElement) {
188                 fName.getText().setFocus();
189             }
190         }
191         super.modelChanged(event);
192     }
193     
194     /* (non-Javadoc)
195      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
196      */

197     public void commit(boolean onSave) {
198         super.commit(onSave);
199         // Only required for form entries
200
fName.commit();
201     }
202 }
203
Popular Tags