KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > rows > ExtensionAttributeRow


1 /*******************************************************************************
2  * Copyright (c) 2003, 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
12 package org.eclipse.pde.internal.ui.editor.plugin.rows;
13
14 import org.eclipse.core.resources.IProject;
15 import org.eclipse.jface.text.IInformationControl;
16 import org.eclipse.pde.core.plugin.IPluginAttribute;
17 import org.eclipse.pde.core.plugin.IPluginElement;
18 import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
19 import org.eclipse.pde.internal.ui.editor.IContextPart;
20 import org.eclipse.pde.internal.ui.editor.text.PDETextHover;
21 import org.eclipse.pde.internal.ui.editor.text.IControlHoverContentProvider;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27 import org.eclipse.ui.forms.IFormColors;
28 import org.eclipse.ui.forms.widgets.FormToolkit;
29 import org.eclipse.ui.forms.widgets.Hyperlink;
30
31 public abstract class ExtensionAttributeRow implements IControlHoverContentProvider {
32     protected IContextPart part;
33     protected Object JavaDoc att;
34     protected IPluginElement input;
35     protected boolean blockNotification;
36     protected boolean dirty;
37     protected IInformationControl fIC;
38     
39     public ExtensionAttributeRow(IContextPart part, ISchemaAttribute att) {
40         this.part = part;
41         this.att = att;
42     }
43     
44     public ExtensionAttributeRow(IContextPart part, IPluginAttribute att) {
45         this.part = part;
46         this.att = att;
47     }
48     
49     public ISchemaAttribute getAttribute() {
50         return (att instanceof ISchemaAttribute) ? (ISchemaAttribute)att:null;
51     }
52     
53     public String JavaDoc getName() {
54         if (att instanceof ISchemaAttribute)
55             return ((ISchemaAttribute)att).getName();
56
57         return ((IPluginAttribute)att).getName();
58     }
59     
60     protected int getUse() {
61         if (att instanceof ISchemaAttribute)
62             return ((ISchemaAttribute)att).getUse();
63         return ISchemaAttribute.OPTIONAL;
64     }
65     
66     protected String JavaDoc getDescription() {
67         if (att instanceof ISchemaAttribute)
68             return ((ISchemaAttribute)att).getDescription();
69         return ""; //$NON-NLS-1$
70
}
71     
72     protected String JavaDoc getValue() {
73         String JavaDoc value= ""; //$NON-NLS-1$
74
if (input!=null) {
75             IPluginAttribute patt = input.getAttribute(getName());
76             if (patt!=null)
77                 value = patt.getValue();
78         }
79         return value;
80     }
81     protected String JavaDoc getPropertyLabel() {
82         String JavaDoc label=getName();
83         if (getUse()==ISchemaAttribute.REQUIRED)
84             label+= "*:"; //$NON-NLS-1$
85
else
86             label+=":"; //$NON-NLS-1$
87
return label;
88     }
89     protected void createLabel(Composite parent, FormToolkit toolkit) {
90         Label label = toolkit.createLabel(parent, getPropertyLabel(), SWT.NULL);
91         label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
92         PDETextHover.addHoverListenerToControl(fIC, label, this);
93     }
94     
95     /**
96      * @param control
97      */

98     protected void createTextHover(Control control) {
99         fIC = PDETextHover.getInformationControlCreator().createInformationControl(control.getShell());
100         fIC.setSizeConstraints(300, 600);
101     }
102     
103     public String JavaDoc getHoverContent(Control c) {
104         if (c instanceof Label || c instanceof Hyperlink)
105             return getDescription();
106         if (c instanceof Text) {
107             String JavaDoc text = ((Text)c).getText();
108             ISchemaAttribute sAtt = getAttribute();
109             String JavaDoc translated = null;
110             if (input != null && sAtt != null && sAtt.isTranslatable() && text.startsWith("%")) //$NON-NLS-1$
111
translated = input.getResourceString(text);
112             if (!text.equals(translated))
113                 return translated;
114         }
115         return null;
116     }
117     
118     /**
119      * @param parent
120      * @param toolkit
121      * @param span
122      */

123     public void createContents(Composite parent, FormToolkit toolkit, int span) {
124         createTextHover(parent);
125     }
126
127     protected abstract void update();
128     public abstract void commit();
129
130     public abstract void setFocus();
131     
132     public boolean isDirty() {
133         return dirty;
134     }
135
136     protected void markDirty() {
137         dirty=true;
138         part.fireSaveNeeded();
139     }
140
141     public void dispose() {
142         if (fIC != null)
143             fIC.dispose();
144     }
145
146     public void setInput(IPluginElement input) {
147         this.input = input;
148         update();
149     }
150     protected IProject getProject() {
151         return part.getPage().getPDEEditor().getCommonProject();
152     }
153 }
154
Popular Tags