KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.jface.viewers.StructuredSelection;
13 import org.eclipse.osgi.util.NLS;
14 import org.eclipse.pde.internal.core.ischema.ISchemaObject;
15 import org.eclipse.pde.internal.core.schema.SchemaElementReference;
16 import org.eclipse.pde.internal.ui.PDEUIMessages;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.ui.forms.IFormColors;
24 import org.eclipse.ui.forms.events.HyperlinkAdapter;
25 import org.eclipse.ui.forms.events.HyperlinkEvent;
26 import org.eclipse.ui.forms.widgets.FormToolkit;
27 import org.eclipse.ui.forms.widgets.Hyperlink;
28
29 public class SchemaElementReferenceDetails extends AbstractSchemaDetails {
30
31     private SchemaElementReference fElement;
32     private Hyperlink fReferenceLink;
33     private Label fRefLabel;
34     
35     public SchemaElementReferenceDetails(ElementSection section) {
36         super(section, true);
37     }
38
39     public void createDetails(Composite parent) {
40         FormToolkit toolkit = getManagedForm().getToolkit();
41         
42         createMinOccurComp(parent, toolkit);
43         createMaxOccurComp(parent, toolkit);
44         
45         fRefLabel = toolkit.createLabel(parent, PDEUIMessages.SchemaElementReferenceDetails_reference);
46         fRefLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
47         fReferenceLink = toolkit.createHyperlink(parent, new String JavaDoc(), SWT.NONE);
48         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
49         gd.horizontalSpan = 2;
50         fReferenceLink.setLayoutData(gd);
51         
52         setText(PDEUIMessages.SchemaElementReferenceDetails_title);
53     }
54
55     public void updateFields(ISchemaObject object) {
56         if (!(object instanceof SchemaElementReference))
57             return;
58         fElement = (SchemaElementReference)object;
59         
60         setDecription(NLS.bind(PDEUIMessages.SchemaElementReferenceDetails_description, fElement.getName()));
61         fReferenceLink.setText(fElement.getName());
62         updateMinOccur(fElement.getMinOccurs());
63         updateMaxOccur(fElement.getMaxOccurs());
64         boolean editable = isEditableElement();
65         fRefLabel.setEnabled(editable);
66         fReferenceLink.setEnabled(editable);
67         enableMinMax(editable);
68     }
69
70     public void hookListeners() {
71         hookMinOccur(new SelectionAdapter() {
72             public void widgetSelected(SelectionEvent e) {
73                 if (blockListeners())
74                     return;
75                 fElement.setMinOccurs(getMinOccur());
76             }
77         });
78         hookMaxOccur(new SelectionAdapter() {
79             public void widgetSelected(SelectionEvent e) {
80                 if (blockListeners())
81                     return;
82                 fElement.setMaxOccurs(getMaxOccur());
83             }
84         });
85         fReferenceLink.addHyperlinkListener(new HyperlinkAdapter() {
86             public void linkActivated(HyperlinkEvent e) {
87                 if (blockListeners())
88                     return;
89                 fireMasterSelection(new StructuredSelection(fElement.getReferencedObject()));
90             }
91         });
92     }
93     
94     /* (non-Javadoc)
95      * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
96      */

97     public void commit(boolean onSave) {
98         super.commit(onSave);
99         // Only required for form entries
100
// NO-OP
101
}
102 }
103
Popular Tags