KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.osgi.util.NLS;
14 import org.eclipse.pde.internal.core.ischema.ISchemaElement;
15 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
16 import org.eclipse.pde.internal.core.schema.SchemaElementReference;
17 import org.eclipse.pde.internal.core.schema.SchemaRootElement;
18 import org.eclipse.pde.internal.ui.PDEUIMessages;
19 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
20 import org.eclipse.pde.internal.ui.parts.FormEntry;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.SelectionAdapter;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.graphics.Color;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.ui.forms.IFormColors;
29 import org.eclipse.ui.forms.widgets.FormToolkit;
30
31 public class SchemaRootElementDetails extends AbstractSchemaDetails {
32
33     private SchemaRootElement fElement;
34     private FormEntry fName;
35     private Button fDepTrue;
36     private Button fDepFalse;
37     private FormEntry fSuggestion;
38     
39     public SchemaRootElementDetails(ElementSection section) {
40         super(section, true);
41     }
42
43     public void createDetails(Composite parent) {
44         FormToolkit toolkit = getManagedForm().getToolkit();
45         Color foreground = toolkit.getColors().getColor(IFormColors.TITLE);
46         
47         fName = new FormEntry(parent, toolkit, PDEUIMessages.SchemaDetails_name, SWT.NONE);
48
49         Label label = toolkit.createLabel(parent, PDEUIMessages.SchemaDetails_deprecated);
50         label.setForeground(foreground);
51         Button[] buttons = createTrueFalseButtons(parent, toolkit, 2);
52         fDepTrue = buttons[0];
53         fDepFalse = buttons[1];
54
55         fSuggestion = new FormEntry(parent, toolkit, PDEUIMessages.SchemaRootElementDetails_replacement, null, false, 6);
56         
57         setText(PDEUIMessages.SchemaElementDetails_title);
58     }
59
60     public void updateFields(ISchemaObject element) {
61         if (!(element instanceof ISchemaElement))
62             return;
63         if (element instanceof SchemaElementReference)
64             element = ((SchemaElementReference)element).getReferencedObject();
65         fElement = (SchemaRootElement)element;
66         if (fElement == null)
67             return;
68         
69         setDecription(NLS.bind(PDEUIMessages.SchemaElementDetails_description, fElement.getName()));
70         fName.setValue(fElement.getName(), true);
71         fDepTrue.setSelection(fElement.isDeprecated());
72         fDepFalse.setSelection(!fElement.isDeprecated());
73         fSuggestion.setValue(fElement.getDeprecatedSuggestion(), true);
74         
75         fName.setEditable(isEditable());
76         fDepTrue.setEnabled(isEditable());
77         fDepFalse.setEnabled(isEditable());
78
79         if (!fElement.isDeprecated()) {
80             fSuggestion.getLabel().setEnabled(false);
81             fSuggestion.getText().setEditable(false);
82         } else {
83             fSuggestion.setEditable(isEditable());
84         }
85     }
86
87     public void hookListeners() {
88         fName.setFormEntryListener(new FormEntryAdapter(this) {
89             public void textValueChanged(FormEntry entry) {
90                 if (blockListeners())
91                     return;
92                 fElement.setName(fName.getValue());
93                 setDecription(NLS.bind(PDEUIMessages.SchemaElementDetails_description, fElement.getName()));
94             }
95         });
96         fDepTrue.addSelectionListener(new SelectionAdapter() {
97             public void widgetSelected(SelectionEvent e) {
98                 if (blockListeners())
99                     return;
100                 boolean deprecated = fDepTrue.getSelection();
101                 fElement.setDeprecatedProperty(deprecated);
102                 fSuggestion.getLabel().setEnabled(deprecated);
103                 fSuggestion.getText().setEditable(deprecated);
104             }
105         });
106         fSuggestion.setFormEntryListener(new FormEntryAdapter(this) {
107             public void textValueChanged(FormEntry entry) {
108                 if (blockListeners())
109                     return;
110                 fElement.setDeprecatedSuggestion(fSuggestion.getValue());
111             }
112         });
113     }
114     
115     /* (non-Javadoc)
116      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
117      */

118     public void commit(boolean onSave) {
119         super.commit(onSave);
120         // Only required for form entries
121
fName.commit();
122         fSuggestion.commit();
123     }
124     
125 }
126
Popular Tags