Source Code Cross Referenced for ExtensionDetails.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » plugin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.ui.editor.plugin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2003, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.jface.dialogs.MessageDialog;
014:        import org.eclipse.jface.viewers.ISelection;
015:        import org.eclipse.jface.viewers.IStructuredSelection;
016:        import org.eclipse.osgi.util.NLS;
017:        import org.eclipse.pde.core.IIdentifiable;
018:        import org.eclipse.pde.core.IModelChangedEvent;
019:        import org.eclipse.pde.core.plugin.IPluginExtension;
020:        import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
021:        import org.eclipse.pde.core.plugin.IPluginModelBase;
022:        import org.eclipse.pde.core.plugin.IPluginObject;
023:        import org.eclipse.pde.internal.core.ICoreConstants;
024:        import org.eclipse.pde.internal.core.PDECore;
025:        import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
026:        import org.eclipse.pde.internal.core.ischema.ISchemaElement;
027:        import org.eclipse.pde.internal.core.schema.Schema;
028:        import org.eclipse.pde.internal.ui.PDEPlugin;
029:        import org.eclipse.pde.internal.ui.PDEPluginImages;
030:        import org.eclipse.pde.internal.ui.PDEUIMessages;
031:        import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
032:        import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
033:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
034:        import org.eclipse.pde.internal.ui.editor.PDESection;
035:        import org.eclipse.pde.internal.ui.editor.actions.OpenSchemaAction;
036:        import org.eclipse.pde.internal.ui.parts.FormEntry;
037:        import org.eclipse.pde.internal.ui.search.FindDeclarationsAction;
038:        import org.eclipse.pde.internal.ui.search.ShowDescriptionAction;
039:        import org.eclipse.swt.SWT;
040:        import org.eclipse.swt.layout.GridData;
041:        import org.eclipse.swt.widgets.Composite;
042:        import org.eclipse.swt.widgets.Control;
043:        import org.eclipse.swt.widgets.Label;
044:        import org.eclipse.ui.forms.IFormPart;
045:        import org.eclipse.ui.forms.events.HyperlinkAdapter;
046:        import org.eclipse.ui.forms.events.HyperlinkEvent;
047:        import org.eclipse.ui.forms.widgets.ExpandableComposite;
048:        import org.eclipse.ui.forms.widgets.FormText;
049:        import org.eclipse.ui.forms.widgets.FormToolkit;
050:        import org.eclipse.ui.forms.widgets.Section;
051:
052:        public class ExtensionDetails extends AbstractPluginElementDetails {
053:            private IPluginExtension input;
054:            private FormEntry id;
055:            private FormEntry name;
056:            private FormText rtext;
057:
058:            private static final String RTEXT_DATA = PDEUIMessages.ExtensionDetails_extensionPointLinks;
059:
060:            /**
061:             * @param masterSection
062:             */
063:            public ExtensionDetails(PDESection masterSection) {
064:                super (masterSection);
065:            }
066:
067:            /* (non-Javadoc)
068:             * @see org.eclipse.ui.forms.IDetailsPage#createContents(org.eclipse.swt.widgets.Composite)
069:             */
070:            public void createContents(Composite parent) {
071:                FormToolkit toolkit = getManagedForm().getToolkit();
072:                parent.setLayout(FormLayoutFactory.createDetailsGridLayout(
073:                        false, 1));
074:
075:                Section section = toolkit.createSection(parent,
076:                        ExpandableComposite.TITLE_BAR | Section.DESCRIPTION);
077:                section.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
078:                section.setText(PDEUIMessages.ExtensionDetails_title);
079:                section.setDescription(PDEUIMessages.ExtensionDetails_desc);
080:                section.setLayout(FormLayoutFactory.createClearGridLayout(
081:                        false, 1));
082:                section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
083:                        | GridData.VERTICAL_ALIGN_BEGINNING));
084:
085:                // Align the master and details section headers (misalignment caused
086:                // by section toolbar icons)
087:                getPage().alignSectionHeaders(getMasterSection().getSection(),
088:                        section);
089:
090:                Composite client = toolkit.createComposite(section);
091:                client.setLayout(FormLayoutFactory
092:                        .createSectionClientGridLayout(false, 2));
093:                client.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
094:
095:                createIDEntryField(toolkit, client);
096:
097:                createNameEntryField(toolkit, client);
098:
099:                createSpacer(toolkit, client, 2);
100:
101:                Composite container = toolkit.createComposite(parent, SWT.NONE);
102:                container.setLayout(FormLayoutFactory
103:                        .createSectionClientGridLayout(false, 1));
104:                container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
105:                        | GridData.VERTICAL_ALIGN_BEGINNING));
106:
107:                rtext = toolkit.createFormText(container, true);
108:                rtext
109:                        .setImage(
110:                                "desc", PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_DOC_SECTION_OBJ)); //$NON-NLS-1$
111:                rtext
112:                        .setImage(
113:                                "open", PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_SCHEMA_OBJ)); //$NON-NLS-1$
114:                rtext
115:                        .setImage(
116:                                "search", PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_PSEARCH_OBJ)); //$NON-NLS-1$
117:                rtext.addHyperlinkListener(new HyperlinkAdapter() {
118:                    public void linkActivated(HyperlinkEvent e) {
119:                        if (e.getHref().equals("search")) { //$NON-NLS-1$
120:                            FindDeclarationsAction findDeclarationsAction = new FindDeclarationsAction(
121:                                    input);
122:                            findDeclarationsAction.run();
123:                        } else if (e.getHref().equals("open")) { //$NON-NLS-1$
124:                            OpenSchemaAction action = new OpenSchemaAction();
125:                            action.setInput(input);
126:                            action.setEnabled(true);
127:                            action.run();
128:                        } else {
129:                            if (input == null || input.getPoint() == null)
130:                                return;
131:                            IPluginExtensionPoint point = PDECore.getDefault()
132:                                    .getExtensionsRegistry()
133:                                    .findExtensionPoint(input.getPoint());
134:                            if (point != null) {
135:                                ShowDescriptionAction showDescAction = new ShowDescriptionAction(
136:                                        point);
137:                                showDescAction.run();
138:                            } else {
139:                                showNoExtensionPointMessage();
140:                            }
141:                        }
142:                    }
143:                });
144:                rtext.setText(RTEXT_DATA, true, false);
145:                id.setEditable(isEditable());
146:                name.setEditable(isEditable());
147:
148:                toolkit.paintBordersFor(client);
149:                section.setClient(client);
150:                IPluginModelBase model = (IPluginModelBase) getPage()
151:                        .getModel();
152:                model.addModelChangedListener(this );
153:                markDetailsPart(section);
154:            }
155:
156:            /**
157:             * @param toolkit
158:             * @param client
159:             */
160:            private void createNameEntryField(FormToolkit toolkit,
161:                    Composite client) {
162:                name = new FormEntry(client, toolkit,
163:                        PDEUIMessages.ExtensionDetails_name, null, false);
164:                name.setFormEntryListener(new FormEntryAdapter(this ) {
165:                    public void textValueChanged(FormEntry entry) {
166:                        if (input != null)
167:                            try {
168:                                input.setName(name.getValue());
169:                            } catch (CoreException e) {
170:                                PDEPlugin.logException(e);
171:                            }
172:                    }
173:                });
174:            }
175:
176:            /**
177:             * @param toolkit
178:             * @param client
179:             */
180:            private void createIDEntryField(FormToolkit toolkit,
181:                    Composite client) {
182:                id = new FormEntry(client, toolkit,
183:                        PDEUIMessages.ExtensionDetails_id, null, false);
184:                id.setFormEntryListener(new FormEntryAdapter(this ) {
185:                    public void textValueChanged(FormEntry entry) {
186:                        if (input != null)
187:                            try {
188:                                input.setId(id.getValue());
189:                            } catch (CoreException e) {
190:                                PDEPlugin.logException(e);
191:                            }
192:                    }
193:                });
194:            }
195:
196:            /* (non-Javadoc)
197:             * @see org.eclipse.ui.forms.IDetailsPage#inputChanged(org.eclipse.jface.viewers.IStructuredSelection)
198:             */
199:            public void selectionChanged(IFormPart part, ISelection selection) {
200:                IStructuredSelection ssel = (IStructuredSelection) selection;
201:                if (ssel.size() == 1) {
202:                    input = (IPluginExtension) ssel.getFirstElement();
203:                } else
204:                    input = null;
205:                update();
206:            }
207:
208:            private void update() {
209:                id.setValue(input != null ? input.getId() : null, true);
210:                name.setValue(input != null ? input.getName() : null, true);
211:
212:                // Update the ID label
213:                updateLabel(isFieldRequired(IIdentifiable.P_ID), id,
214:                        PDEUIMessages.ExtensionDetails_id);
215:                // Update the Name label
216:                updateLabel(isFieldRequired(IPluginObject.P_NAME), name,
217:                        PDEUIMessages.ExtensionDetails_name);
218:            }
219:
220:            /**
221:             * Denote a field as required by updating their label
222:             * @param attributeName
223:             * @param field
224:             */
225:            private boolean isFieldRequired(String attributeName) {
226:                // Ensure we have input
227:                if (input == null) {
228:                    return false;
229:                }
230:                // Get the associated schema
231:                Object object = input.getSchema();
232:                // Ensure we have a schema
233:                if ((object == null) || (object instanceof  Schema) == false) {
234:                    return false;
235:                }
236:                Schema schema = (Schema) object;
237:                // Find the extension element
238:                ISchemaElement element = schema
239:                        .findElement(ICoreConstants.EXTENSION_NAME);
240:                // Ensure we found the element
241:                if (element == null) {
242:                    return false;
243:                }
244:                // Get the attribute
245:                ISchemaAttribute attribute = element
246:                        .getAttribute(attributeName);
247:                // Ensure we found the attribute
248:                if (attribute == null) {
249:                    return false;
250:                }
251:                // Determine whether the attribute is required
252:                if (attribute.getUse() == ISchemaAttribute.REQUIRED) {
253:                    return true;
254:                }
255:                return false;
256:            }
257:
258:            /**
259:             * @param field
260:             * @param required
261:             */
262:            private void updateLabel(boolean required, FormEntry field,
263:                    String label) {
264:                // Get the label
265:                Control control = field.getLabel();
266:                // Ensure label is defined
267:                if ((control == null) || ((control instanceof  Label) == false)) {
268:                    return;
269:                }
270:                Label labelControl = ((Label) control);
271:                // If the label is required, add the '*' to indicate that
272:                if (required) {
273:                    labelControl.setText(label + '*' + ':');
274:                } else {
275:                    labelControl.setText(label + ':');
276:                }
277:                // Force the label's parent composite to relayout because 
278:                // clippage can occur when updating the text
279:                labelControl.getParent().layout();
280:            }
281:
282:            public void cancelEdit() {
283:                id.cancelEdit();
284:                name.cancelEdit();
285:                super .cancelEdit();
286:            }
287:
288:            /* (non-Javadoc)
289:             * @see org.eclipse.ui.forms.IDetailsPage#commit()
290:             */
291:            public void commit(boolean onSave) {
292:                id.commit();
293:                name.commit();
294:                super .commit(onSave);
295:            }
296:
297:            /* (non-Javadoc)
298:             * @see org.eclipse.ui.forms.IDetailsPage#setFocus()
299:             */
300:            public void setFocus() {
301:                id.getText().setFocus();
302:            }
303:
304:            public void dispose() {
305:                IPluginModelBase model = (IPluginModelBase) getPage()
306:                        .getModel();
307:                if (model != null)
308:                    model.removeModelChangedListener(this );
309:                super .dispose();
310:            }
311:
312:            public void modelChanged(IModelChangedEvent e) {
313:                if (e.getChangeType() == IModelChangedEvent.CHANGE) {
314:                    Object obj = e.getChangedObjects()[0];
315:                    if (obj.equals(input))
316:                        refresh();
317:                }
318:            }
319:
320:            /* (non-Javadoc)
321:             * @see org.eclipse.ui.forms.IDetailsPage#refresh()
322:             */
323:            public void refresh() {
324:                update();
325:                super .refresh();
326:            }
327:
328:            /* (non-Javadoc)
329:             * @see org.eclipse.pde.internal.ui.neweditor.IContextPart#fireSaveNeeded()
330:             */
331:            public void fireSaveNeeded() {
332:                markDirty();
333:                PDEFormPage page = (PDEFormPage) getManagedForm()
334:                        .getContainer();
335:                page.getPDEEditor().fireSaveNeeded(getContextId(), false);
336:            }
337:
338:            /* (non-Javadoc)
339:             * @see org.eclipse.pde.internal.ui.neweditor.IContextPart#getContextId()
340:             */
341:            public String getContextId() {
342:                return PluginInputContext.CONTEXT_ID;
343:            }
344:
345:            public PDEFormPage getPage() {
346:                return (PDEFormPage) getManagedForm().getContainer();
347:            }
348:
349:            public boolean isEditable() {
350:                return getPage().getPDEEditor().getAggregateModel()
351:                        .isEditable();
352:            }
353:
354:            private void showNoExtensionPointMessage() {
355:                String title = PDEUIMessages.ExtensionDetails_noPoint_title;
356:                String message = NLS.bind(
357:                        PDEUIMessages.ShowDescriptionAction_noPoint_desc, input
358:                                .getPoint());
359:
360:                MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(),
361:                        title, message);
362:            }
363:        }
w_w__w__.__j___a___v___a__2___s___.co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.