Source Code Cross Referenced for GeneralInfoSection.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) 2000, 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:         *     Peter Friese <peter.friese@gentleware.com> - bug 199431
011:         *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
012:
013:        import org.eclipse.core.runtime.CoreException;
014:        import org.eclipse.jface.dialogs.IMessageProvider;
015:        import org.eclipse.pde.core.IBaseModel;
016:        import org.eclipse.pde.core.IModelChangeProvider;
017:        import org.eclipse.pde.core.IModelChangedEvent;
018:        import org.eclipse.pde.core.plugin.IPluginBase;
019:        import org.eclipse.pde.core.plugin.IPluginModelBase;
020:        import org.eclipse.pde.core.plugin.PluginRegistry;
021:        import org.eclipse.pde.internal.core.ibundle.IBundle;
022:        import org.eclipse.pde.internal.core.ibundle.IBundleModel;
023:        import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
024:        import org.eclipse.pde.internal.core.text.bundle.BundleSymbolicNameHeader;
025:        import org.eclipse.pde.internal.ui.PDEPlugin;
026:        import org.eclipse.pde.internal.ui.PDEUIMessages;
027:        import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
028:        import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
029:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
030:        import org.eclipse.pde.internal.ui.editor.PDESection;
031:        import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
032:        import org.eclipse.pde.internal.ui.editor.validation.ControlValidationUtility;
033:        import org.eclipse.pde.internal.ui.editor.validation.TextValidator;
034:        import org.eclipse.pde.internal.ui.parts.FormEntry;
035:        import org.eclipse.swt.SWT;
036:        import org.eclipse.swt.dnd.Clipboard;
037:        import org.eclipse.swt.events.SelectionAdapter;
038:        import org.eclipse.swt.events.SelectionEvent;
039:        import org.eclipse.swt.widgets.Button;
040:        import org.eclipse.swt.widgets.Composite;
041:        import org.eclipse.swt.widgets.Display;
042:        import org.eclipse.swt.widgets.Text;
043:        import org.eclipse.ui.IActionBars;
044:        import org.eclipse.ui.forms.widgets.FormToolkit;
045:        import org.eclipse.ui.forms.widgets.Section;
046:        import org.eclipse.ui.forms.widgets.TableWrapData;
047:        import org.osgi.framework.Constants;
048:        import org.eclipse.pde.internal.core.text.bundle.Bundle;
049:
050:        public abstract class GeneralInfoSection extends PDESection {
051:            private static String PLATFORM_FILTER = "Eclipse-PlatformFilter"; //$NON-NLS-1$
052:
053:            private FormEntry fIdEntry;
054:            private FormEntry fVersionEntry;
055:            private FormEntry fNameEntry;
056:            private FormEntry fProviderEntry;
057:            private FormEntry fPlatformFilterEntry;
058:
059:            private TextValidator fIdEntryValidator;
060:
061:            private TextValidator fVersionEntryValidator;
062:
063:            private TextValidator fNameEntryValidator;
064:
065:            private TextValidator fProviderEntryValidator;
066:
067:            private TextValidator fPlatformEntryValidator;
068:
069:            private IPluginModelBase fModel;
070:
071:            protected Button fSingleton;
072:
073:            public GeneralInfoSection(PDEFormPage page, Composite parent) {
074:                super (page, parent, Section.DESCRIPTION);
075:                createClient(getSection(), page.getEditor().getToolkit());
076:            }
077:
078:            /*
079:             * (non-Javadoc)
080:             * 
081:             * @see org.eclipse.pde.internal.ui.neweditor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section,
082:             *      org.eclipse.ui.forms.widgets.FormToolkit)
083:             */
084:            protected void createClient(Section section, FormToolkit toolkit) {
085:                section
086:                        .setText(PDEUIMessages.ManifestEditor_PluginSpecSection_title);
087:                section.setLayout(FormLayoutFactory.createClearTableWrapLayout(
088:                        false, 1));
089:                TableWrapData data = new TableWrapData(TableWrapData.FILL_GRAB);
090:                section.setLayoutData(data);
091:
092:                section.setDescription(getSectionDescription());
093:                Composite client = toolkit.createComposite(section);
094:                client.setLayout(FormLayoutFactory
095:                        .createSectionClientTableWrapLayout(false, 3));
096:                section.setClient(client);
097:
098:                IActionBars actionBars = getPage().getPDEEditor()
099:                        .getEditorSite().getActionBars();
100:                createIDEntry(client, toolkit, actionBars);
101:                createVersionEntry(client, toolkit, actionBars);
102:                createNameEntry(client, toolkit, actionBars);
103:                createProviderEntry(client, toolkit, actionBars);
104:                if (isBundle()
105:                        && ((ManifestEditor) getPage().getEditor()).isEquinox())
106:                    createPlatformFilterEntry(client, toolkit, actionBars);
107:                createSpecificControls(client, toolkit, actionBars);
108:                toolkit.paintBordersFor(client);
109:
110:                addListeners();
111:            }
112:
113:            protected abstract String getSectionDescription();
114:
115:            protected abstract void createSpecificControls(Composite parent,
116:                    FormToolkit toolkit, IActionBars actionBars);
117:
118:            protected IPluginBase getPluginBase() {
119:                IBaseModel model = getPage().getPDEEditor().getAggregateModel();
120:                return ((IPluginModelBase) model).getPluginBase();
121:            }
122:
123:            /**
124:             * Not using the aggregate model from the form editor because it is 
125:             * a different model instance from the one used by the bundle error
126:             * reporter.  Things get out of sync between the form validator and 
127:             * source validator
128:             * @return
129:             */
130:            protected IPluginModelBase getModelBase() {
131:                // Find the model only on the first call
132:                if (fModel == null) {
133:                    fModel = PluginRegistry.findModel(getProject());
134:                }
135:                return fModel;
136:            }
137:
138:            protected boolean isBundle() {
139:                return getBundleContext() != null;
140:            }
141:
142:            private BundleInputContext getBundleContext() {
143:                InputContextManager manager = getPage().getPDEEditor()
144:                        .getContextManager();
145:                return (BundleInputContext) manager
146:                        .findContext(BundleInputContext.CONTEXT_ID);
147:            }
148:
149:            protected IBundle getBundle() {
150:                BundleInputContext context = getBundleContext();
151:                if (context != null) {
152:                    IBundleModel model = (IBundleModel) context.getModel();
153:                    return model.getBundle();
154:                }
155:                return null;
156:            }
157:
158:            private void createIDEntry(Composite client, FormToolkit toolkit,
159:                    IActionBars actionBars) {
160:                fIdEntry = new FormEntry(client, toolkit,
161:                        PDEUIMessages.GeneralInfoSection_id, null, false);
162:                fIdEntry.setFormEntryListener(new FormEntryAdapter(this ,
163:                        actionBars) {
164:                    public void textValueChanged(FormEntry entry) {
165:                        try {
166:                            getPluginBase().setId(entry.getValue());
167:                        } catch (CoreException e) {
168:                            PDEPlugin.logException(e);
169:                        }
170:                    }
171:                });
172:                fIdEntry.setEditable(isEditable());
173:                // Create validator
174:                fIdEntryValidator = new TextValidator(getManagedForm(),
175:                        fIdEntry.getText(), getProject(), true) {
176:                    protected boolean validateControl() {
177:                        return validateIdEntry();
178:                    }
179:                };
180:            }
181:
182:            /**
183:             * @return
184:             */
185:            private boolean validateIdEntry() {
186:                // Value must be specified
187:                return ControlValidationUtility.validateRequiredField(fIdEntry
188:                        .getText().getText(), fIdEntryValidator,
189:                        IMessageProvider.ERROR);
190:            }
191:
192:            private void createVersionEntry(Composite client,
193:                    FormToolkit toolkit, IActionBars actionBars) {
194:                fVersionEntry = new FormEntry(client, toolkit,
195:                        PDEUIMessages.GeneralInfoSection_version, null, false);
196:                fVersionEntry.setFormEntryListener(new FormEntryAdapter(this ,
197:                        actionBars) {
198:                    public void textValueChanged(FormEntry entry) {
199:                        try {
200:                            getPluginBase().setVersion(entry.getValue());
201:                        } catch (CoreException e) {
202:                            PDEPlugin.logException(e);
203:                        }
204:                    }
205:                });
206:                fVersionEntry.setEditable(isEditable());
207:                // Create validator
208:                fVersionEntryValidator = new TextValidator(getManagedForm(),
209:                        fVersionEntry.getText(), getProject(), true) {
210:                    protected boolean validateControl() {
211:                        return validateVersionEntry();
212:                    }
213:                };
214:            }
215:
216:            /**
217:             * @return
218:             */
219:            private boolean validateVersionEntry() {
220:                // Value must be specified
221:                if (ControlValidationUtility.validateRequiredField(
222:                        fVersionEntry.getText().getText(),
223:                        fVersionEntryValidator, IMessageProvider.ERROR) == false) {
224:                    return false;
225:                }
226:                // Value must be a valid version
227:                return ControlValidationUtility.validateVersionField(
228:                        fVersionEntry.getText().getText(),
229:                        fVersionEntryValidator);
230:            }
231:
232:            private void createNameEntry(Composite client, FormToolkit toolkit,
233:                    IActionBars actionBars) {
234:                fNameEntry = new FormEntry(client, toolkit,
235:                        PDEUIMessages.GeneralInfoSection_name, null, false);
236:                fNameEntry.setFormEntryListener(new FormEntryAdapter(this ,
237:                        actionBars) {
238:                    public void textValueChanged(FormEntry entry) {
239:                        try {
240:                            getPluginBase().setName(entry.getValue());
241:                        } catch (CoreException e) {
242:                            PDEPlugin.logException(e);
243:                        }
244:                    }
245:                });
246:                fNameEntry.setEditable(isEditable());
247:                // Create validator
248:                fNameEntryValidator = new TextValidator(getManagedForm(),
249:                        fNameEntry.getText(), getProject(), true) {
250:                    protected boolean validateControl() {
251:                        return validateNameEntry();
252:                    }
253:                };
254:            }
255:
256:            /**
257:             * @return
258:             */
259:            private boolean validateNameEntry() {
260:                // Value must be specified
261:                if (ControlValidationUtility.validateRequiredField(fNameEntry
262:                        .getText().getText(), fNameEntryValidator,
263:                        IMessageProvider.ERROR) == false) {
264:                    return false;
265:                }
266:                // Value must be externalized
267:                return ControlValidationUtility.validateTranslatableField(
268:                        fNameEntry.getText().getText(), fNameEntryValidator,
269:                        getModelBase(), getProject());
270:            }
271:
272:            private void createProviderEntry(Composite client,
273:                    FormToolkit toolkit, IActionBars actionBars) {
274:                fProviderEntry = new FormEntry(client, toolkit,
275:                        PDEUIMessages.GeneralInfoSection_provider, null, false);
276:                fProviderEntry.setFormEntryListener(new FormEntryAdapter(this ,
277:                        actionBars) {
278:                    public void textValueChanged(FormEntry entry) {
279:                        try {
280:                            getPluginBase().setProviderName(entry.getValue());
281:                        } catch (CoreException e) {
282:                            PDEPlugin.logException(e);
283:                        }
284:                    }
285:                });
286:                fProviderEntry.setEditable(isEditable());
287:                // Create validator
288:                fProviderEntryValidator = new TextValidator(getManagedForm(),
289:                        fProviderEntry.getText(), getProject(), true) {
290:                    protected boolean validateControl() {
291:                        return validateProviderEntry();
292:                    }
293:                };
294:            }
295:
296:            /**
297:             * @return
298:             */
299:            private boolean validateProviderEntry() {
300:                // No validation required for an optional field
301:                if (fProviderEntry.getText().getText().length() == 0) {
302:                    return true;
303:                }
304:                // Value must be externalized
305:                return ControlValidationUtility.validateTranslatableField(
306:                        fProviderEntry.getText().getText(),
307:                        fProviderEntryValidator, getModelBase(), getProject());
308:            }
309:
310:            private void createPlatformFilterEntry(Composite client,
311:                    FormToolkit toolkit, IActionBars actionBars) {
312:                fPlatformFilterEntry = new FormEntry(client, toolkit,
313:                        PDEUIMessages.GeneralInfoSection_platformFilter, null,
314:                        false);
315:                fPlatformFilterEntry.setFormEntryListener(new FormEntryAdapter(
316:                        this , actionBars) {
317:                    public void textValueChanged(FormEntry entry) {
318:                        getBundle().setHeader(PLATFORM_FILTER,
319:                                fPlatformFilterEntry.getValue());
320:                    }
321:                });
322:                fPlatformFilterEntry.setEditable(isEditable());
323:                // Create validator
324:                fPlatformEntryValidator = new TextValidator(getManagedForm(),
325:                        fPlatformFilterEntry.getText(), getProject(), true) {
326:                    protected boolean validateControl() {
327:                        return validatePlatformEntry();
328:                    }
329:                };
330:            }
331:
332:            /**
333:             * @return
334:             */
335:            private boolean validatePlatformEntry() {
336:                // No validation required for an optional field
337:                if (fPlatformFilterEntry.getText().getText().length() == 0) {
338:                    return true;
339:                }
340:                // Value must match the current environment and contain valid syntax
341:                return ControlValidationUtility.validatePlatformFilterField(
342:                        fPlatformFilterEntry.getText().getText(),
343:                        fPlatformEntryValidator);
344:            }
345:
346:            public void commit(boolean onSave) {
347:                fIdEntry.commit();
348:                fVersionEntry.commit();
349:                fNameEntry.commit();
350:                fProviderEntry.commit();
351:                if (fPlatformFilterEntry != null)
352:                    fPlatformFilterEntry.commit();
353:                super .commit(onSave);
354:            }
355:
356:            /*
357:             * (non-Javadoc)
358:             * 
359:             * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
360:             */
361:            public void modelChanged(IModelChangedEvent e) {
362:                if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
363:                    markStale();
364:                    return;
365:                }
366:                refresh();
367:                if (e.getChangeType() == IModelChangedEvent.CHANGE) {
368:                    Object obj = e.getChangedObjects()[0];
369:                    if (obj instanceof  IPluginBase) {
370:                        String property = e.getChangedProperty();
371:                        if (property != null
372:                                && property.equals(getPage().getPDEEditor()
373:                                        .getTitleProperty()))
374:                            getPage().getPDEEditor().updateTitle();
375:                    }
376:                }
377:            }
378:
379:            public void refresh() {
380:                IPluginModelBase model = (IPluginModelBase) getPage()
381:                        .getPDEEditor().getContextManager().getAggregateModel();
382:                IPluginBase pluginBase = model.getPluginBase();
383:                fIdEntry.setValue(pluginBase.getId(), true);
384:                fNameEntry.setValue(pluginBase.getName(), true);
385:                fVersionEntry.setValue(pluginBase.getVersion(), true);
386:                fProviderEntry.setValue(pluginBase.getProviderName(), true);
387:                if (fPlatformFilterEntry != null) {
388:                    IBundle bundle = getBundle();
389:                    if (bundle != null)
390:                        fPlatformFilterEntry.setValue(bundle
391:                                .getHeader(PLATFORM_FILTER), true);
392:                }
393:                getPage().getPDEEditor().updateTitle();
394:                if (fSingleton != null) {
395:                    IManifestHeader header = getSingletonHeader();
396:                    fSingleton
397:                            .setSelection(header instanceof  BundleSymbolicNameHeader
398:                                    && ((BundleSymbolicNameHeader) header)
399:                                            .isSingleton());
400:                }
401:                super .refresh();
402:            }
403:
404:            public void cancelEdit() {
405:                fIdEntry.cancelEdit();
406:                fNameEntry.cancelEdit();
407:                fVersionEntry.cancelEdit();
408:                fProviderEntry.cancelEdit();
409:                if (fPlatformFilterEntry != null)
410:                    fPlatformFilterEntry.cancelEdit();
411:                super .cancelEdit();
412:            }
413:
414:            public void dispose() {
415:                removeListeners();
416:                super .dispose();
417:            }
418:
419:            protected void removeListeners() {
420:                IBaseModel model = getPage().getModel();
421:                if (model instanceof  IModelChangeProvider)
422:                    ((IModelChangeProvider) model)
423:                            .removeModelChangedListener(this );
424:            }
425:
426:            protected void addListeners() {
427:                IBaseModel model = getPage().getModel();
428:                if (model instanceof  IModelChangeProvider)
429:                    ((IModelChangeProvider) model)
430:                            .addModelChangedListener(this );
431:            }
432:
433:            public boolean canPaste(Clipboard clipboard) {
434:                Display d = getSection().getDisplay();
435:                return (d.getFocusControl() instanceof  Text);
436:            }
437:
438:            IManifestHeader getSingletonHeader() {
439:                IBundle bundle = getBundle();
440:                if (bundle instanceof  Bundle) {
441:                    IManifestHeader header = bundle
442:                            .getManifestHeader(Constants.BUNDLE_SYMBOLICNAME);
443:                    return header;
444:                }
445:                return null;
446:            }
447:
448:            protected void createSingleton(Composite parent,
449:                    FormToolkit toolkit, IActionBars actionBars, String label) {
450:                fSingleton = toolkit.createButton(parent, label, SWT.CHECK);
451:                TableWrapData td = new TableWrapData();
452:                td.colspan = 3;
453:                fSingleton.setLayoutData(td);
454:                fSingleton.setEnabled(isEditable());
455:                fSingleton.addSelectionListener(new SelectionAdapter() {
456:                    public void widgetSelected(SelectionEvent e) {
457:                        IManifestHeader header = getSingletonHeader();
458:                        if (header instanceof  BundleSymbolicNameHeader)
459:                            ((BundleSymbolicNameHeader) header)
460:                                    .setSingleton(fSingleton.getSelection());
461:                    }
462:                });
463:            }
464:
465:        }
w_w___w._jav_a__2s__.__c_om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.