Source Code Cross Referenced for ContentSection.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » target » 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.target 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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:         *     Bartosz Michalik <bartosz.michalik@gmail.com> - bug 187646
011:         *******************************************************************************/package org.eclipse.pde.internal.ui.editor.target;
012:
013:        import java.util.ArrayList;
014:        import java.util.Collection;
015:        import java.util.HashSet;
016:        import java.util.Iterator;
017:        import java.util.TreeMap;
018:
019:        import org.eclipse.core.resources.IFile;
020:        import org.eclipse.core.resources.IProject;
021:        import org.eclipse.core.runtime.CoreException;
022:        import org.eclipse.core.runtime.IAdaptable;
023:        import org.eclipse.core.runtime.QualifiedName;
024:        import org.eclipse.jdt.core.IJavaProject;
025:        import org.eclipse.jface.action.Action;
026:        import org.eclipse.jface.action.IMenuManager;
027:        import org.eclipse.jface.action.Separator;
028:        import org.eclipse.jface.viewers.ISelectionChangedListener;
029:        import org.eclipse.jface.viewers.IStructuredSelection;
030:        import org.eclipse.jface.viewers.SelectionChangedEvent;
031:        import org.eclipse.jface.viewers.StructuredSelection;
032:        import org.eclipse.jface.viewers.TableViewer;
033:        import org.eclipse.jface.viewers.Viewer;
034:        import org.eclipse.jface.viewers.ViewerComparator;
035:        import org.eclipse.jface.window.Window;
036:        import org.eclipse.osgi.service.resolver.BundleDescription;
037:        import org.eclipse.pde.core.IModelChangedEvent;
038:        import org.eclipse.pde.core.plugin.IPluginModelBase;
039:        import org.eclipse.pde.core.plugin.PluginRegistry;
040:        import org.eclipse.pde.internal.core.PDECore;
041:        import org.eclipse.pde.internal.core.TargetPlatformHelper;
042:        import org.eclipse.pde.internal.core.ifeature.IFeature;
043:        import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
044:        import org.eclipse.pde.internal.core.itarget.ITarget;
045:        import org.eclipse.pde.internal.core.itarget.ITargetFeature;
046:        import org.eclipse.pde.internal.core.itarget.ITargetModel;
047:        import org.eclipse.pde.internal.core.itarget.ITargetModelFactory;
048:        import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
049:        import org.eclipse.pde.internal.core.plugin.ExternalPluginModelBase;
050:        import org.eclipse.pde.internal.ui.IPDEUIConstants;
051:        import org.eclipse.pde.internal.ui.PDEPlugin;
052:        import org.eclipse.pde.internal.ui.PDEPluginImages;
053:        import org.eclipse.pde.internal.ui.PDEUIMessages;
054:        import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
055:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
056:        import org.eclipse.pde.internal.ui.editor.TableSection;
057:        import org.eclipse.pde.internal.ui.editor.feature.FeatureEditor;
058:        import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
059:        import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
060:        import org.eclipse.pde.internal.ui.parts.ConditionalListSelectionDialog;
061:        import org.eclipse.pde.internal.ui.parts.TablePart;
062:        import org.eclipse.pde.internal.ui.search.dependencies.DependencyCalculator;
063:        import org.eclipse.pde.internal.ui.util.PersistablePluginObject;
064:        import org.eclipse.pde.internal.ui.wizards.FeatureSelectionDialog;
065:        import org.eclipse.swt.SWT;
066:        import org.eclipse.swt.custom.CTabFolder;
067:        import org.eclipse.swt.custom.CTabItem;
068:        import org.eclipse.swt.events.SelectionAdapter;
069:        import org.eclipse.swt.events.SelectionEvent;
070:        import org.eclipse.swt.graphics.Color;
071:        import org.eclipse.swt.graphics.Image;
072:        import org.eclipse.swt.layout.GridData;
073:        import org.eclipse.swt.widgets.Button;
074:        import org.eclipse.swt.widgets.Composite;
075:        import org.eclipse.swt.widgets.Table;
076:        import org.eclipse.swt.widgets.TableItem;
077:        import org.eclipse.ui.IEditorInput;
078:        import org.eclipse.ui.IFileEditorInput;
079:        import org.eclipse.ui.IWorkingSet;
080:        import org.eclipse.ui.IWorkingSetManager;
081:        import org.eclipse.ui.PlatformUI;
082:        import org.eclipse.ui.actions.ActionFactory;
083:        import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
084:        import org.eclipse.ui.forms.IFormColors;
085:        import org.eclipse.ui.forms.widgets.FormToolkit;
086:        import org.eclipse.ui.forms.widgets.Section;
087:
088:        public class ContentSection extends TableSection {
089:
090:            class ContentProvider extends DefaultTableProvider {
091:                public Object[] getElements(Object parent) {
092:                    ITarget target = getTarget();
093:                    if (fLastTab == 0)
094:                        return target.getPlugins();
095:                    return target.getFeatures();
096:                }
097:            }
098:
099:            private static final String[] TAB_LABELS = new String[2];
100:            static {
101:                TAB_LABELS[0] = PDEUIMessages.ContentSection_plugins;
102:                TAB_LABELS[1] = PDEUIMessages.ContentSection_features;
103:            }
104:
105:            private static final String[] BUTTONS = new String[5];
106:            static {
107:                BUTTONS[0] = PDEUIMessages.ContentSection_add;
108:                BUTTONS[1] = PDEUIMessages.ContentSection_remove;
109:                BUTTONS[2] = PDEUIMessages.ContentSection_removeAll;
110:                BUTTONS[3] = PDEUIMessages.ContentSection_workingSet;
111:                BUTTONS[4] = PDEUIMessages.ContentSection_required;
112:            }
113:
114:            private TableViewer fContentViewer;
115:            private CTabFolder fTabFolder;
116:            private int fLastTab;
117:            private Button fUseAllPlugins;
118:            private Button fUseSelectedPlugins;
119:            private Image[] fTabImages;
120:            private Button fIncludeOptionalButton;
121:            public static final QualifiedName OPTIONAL_PROPERTY = new QualifiedName(
122:                    IPDEUIConstants.PLUGIN_ID, "target.includeOptional"); //$NON-NLS-1$
123:
124:            public ContentSection(PDEFormPage page, Composite parent) {
125:                super (page, parent, Section.DESCRIPTION, BUTTONS);
126:            }
127:
128:            /* (non-Javadoc)
129:             * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
130:             */
131:            protected void createClient(Section section, FormToolkit toolkit) {
132:                section.setLayout(FormLayoutFactory.createClearGridLayout(
133:                        false, 1));
134:                Composite client = toolkit.createComposite(section);
135:                client.setLayout(FormLayoutFactory
136:                        .createSectionClientGridLayout(false, 2));
137:                client.setLayoutData(new GridData(GridData.FILL_BOTH));
138:
139:                // create radio buttons
140:                SelectionAdapter radioListener = new SelectionAdapter() {
141:                    public void widgetSelected(SelectionEvent e) {
142:                        getTarget().setUseAllPlugins(
143:                                fUseAllPlugins.getSelection());
144:                    }
145:                };
146:
147:                fUseAllPlugins = toolkit.createButton(client,
148:                        PDEUIMessages.ContentSection_allTarget, SWT.RADIO);
149:                fUseAllPlugins.addSelectionListener(radioListener);
150:                GridData gd = new GridData();
151:                gd.horizontalSpan = 2;
152:                fUseAllPlugins.setLayoutData(gd);
153:
154:                fUseSelectedPlugins = toolkit.createButton(client,
155:                        PDEUIMessages.ContentSection_selectedOnly, SWT.RADIO);
156:                gd = new GridData();
157:                gd.horizontalSpan = 2;
158:                gd.verticalIndent = 5;
159:                fUseSelectedPlugins.setLayoutData(gd);
160:
161:                // create tab folder widget
162:                fTabFolder = new CTabFolder(client, SWT.FLAT | SWT.TOP);
163:                gd = new GridData(GridData.FILL_HORIZONTAL);
164:                gd.heightHint = 2;
165:                gd.horizontalSpan = 2;
166:                gd.horizontalIndent = 15;
167:                fTabFolder.setLayoutData(gd);
168:                toolkit.adapt(fTabFolder, true, true);
169:                toolkit.getColors().initializeSectionToolBarColors();
170:                Color selectedColor = toolkit.getColors().getColor(
171:                        IFormColors.TB_BG);
172:                fTabFolder.setSelectionBackground(new Color[] { selectedColor,
173:                        toolkit.getColors().getBackground() },
174:                        new int[] { 100 }, true);
175:                fTabFolder.addSelectionListener(new SelectionAdapter() {
176:                    public void widgetSelected(SelectionEvent e) {
177:                        refresh();
178:                    }
179:                });
180:
181:                createTabs();
182:
183:                // create table widget
184:                createViewerPartControl(client, SWT.MULTI, 2, toolkit);
185:
186:                TablePart tablePart = getTablePart();
187:                GridData data = (GridData) tablePart.getControl()
188:                        .getLayoutData();
189:                data.grabExcessVerticalSpace = true;
190:                data.grabExcessHorizontalSpace = true;
191:                data.horizontalIndent = 15;
192:                fContentViewer = tablePart.getTableViewer();
193:                fContentViewer.setContentProvider(new ContentProvider());
194:                fContentViewer.setLabelProvider(PDEPlugin.getDefault()
195:                        .getLabelProvider());
196:                fContentViewer.setComparator(new ViewerComparator() {
197:                    public int compare(Viewer viewer, Object e1, Object e2) {
198:                        if (e1 instanceof  ITargetPlugin) {
199:                            ITargetPlugin p1 = (ITargetPlugin) e1;
200:                            ITargetPlugin p2 = (ITargetPlugin) e2;
201:                            return super 
202:                                    .compare(viewer, p1.getId(), p2.getId());
203:                        } // else 
204:                        ITargetFeature f1 = (ITargetFeature) e1;
205:                        ITargetFeature f2 = (ITargetFeature) e2;
206:                        return super .compare(viewer, f1.getId(), f2.getId());
207:                    }
208:                });
209:                fContentViewer.setInput(PDECore.getDefault().getModelManager());
210:                fContentViewer
211:                        .addSelectionChangedListener(new ISelectionChangedListener() {
212:                            public void selectionChanged(
213:                                    SelectionChangedEvent event) {
214:                                updateEnablement();
215:                            }
216:                        });
217:
218:                createOptionalDependenciesButton(client);
219:
220:                toolkit.paintBordersFor(client);
221:                section.setClient(client);
222:                section.setText(PDEUIMessages.ContentSection_targetContent);
223:                section
224:                        .setDescription(PDEUIMessages.ContentSection_targetContentDesc);
225:                section.setLayoutData(new GridData(GridData.FILL_BOTH));
226:                updateEnablement();
227:                getModel().addModelChangedListener(this );
228:            }
229:
230:            private void createOptionalDependenciesButton(Composite client) {
231:                if (isEditable()) {
232:                    fIncludeOptionalButton = new Button(client, SWT.CHECK);
233:                    fIncludeOptionalButton
234:                            .setText(PDEUIMessages.ContentSection_includeOptional);
235:                    // initialize value
236:                    IEditorInput input = getPage().getEditorInput();
237:                    if (input instanceof  IFileEditorInput) {
238:                        IFile file = ((IFileEditorInput) input).getFile();
239:                        try {
240:                            fIncludeOptionalButton
241:                                    .setSelection("true".equals(file.getPersistentProperty(OPTIONAL_PROPERTY))); //$NON-NLS-1$
242:                        } catch (CoreException e) {
243:                        }
244:                    }
245:                    fIncludeOptionalButton.setEnabled(!getTarget()
246:                            .useAllPlugins());
247:                    // create listener to save value when the checkbox is changed
248:                    fIncludeOptionalButton
249:                            .addSelectionListener(new SelectionAdapter() {
250:                                public void widgetSelected(SelectionEvent e) {
251:                                    IEditorInput input = getPage()
252:                                            .getEditorInput();
253:                                    if (input instanceof  IFileEditorInput) {
254:                                        IFile file = ((IFileEditorInput) input)
255:                                                .getFile();
256:                                        try {
257:                                            file
258:                                                    .setPersistentProperty(
259:                                                            OPTIONAL_PROPERTY,
260:                                                            fIncludeOptionalButton
261:                                                                    .getSelection() ? "true" : null); //$NON-NLS-1$
262:                                        } catch (CoreException e1) {
263:                                        }
264:                                    }
265:                                }
266:                            });
267:                }
268:            }
269:
270:            /* (non-Javadoc)
271:             * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#buttonSelected(int)
272:             */
273:            protected void buttonSelected(int index) {
274:                switch (index) {
275:                case 0:
276:                    handleAdd();
277:                    break;
278:                case 1:
279:                    handleDelete();
280:                    break;
281:                case 2:
282:                    handleRemoveAll();
283:                    break;
284:                case 3:
285:                    handleAddWorkingSet();
286:                    break;
287:                case 4:
288:                    handleAddRequired(getTarget().getPlugins(),
289:                            fIncludeOptionalButton.getSelection());
290:                }
291:            }
292:
293:            private void createTabs() {
294:                fTabImages = new Image[] {
295:                        PDEPluginImages.DESC_PLUGIN_OBJ.createImage(),
296:                        PDEPluginImages.DESC_FEATURE_OBJ.createImage() };
297:                for (int i = 0; i < TAB_LABELS.length; i++) {
298:                    CTabItem item = new CTabItem(fTabFolder, SWT.NULL);
299:                    item.setText(TAB_LABELS[i]);
300:                    item.setImage(fTabImages[i]);
301:                }
302:                fLastTab = 0;
303:                fTabFolder.setSelection(fLastTab);
304:            }
305:
306:            /* (non-Javadoc)
307:             * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
308:             */
309:            public void refresh() {
310:                fLastTab = fTabFolder.getSelectionIndex();
311:                fContentViewer.refresh();
312:                updateEnablement();
313:                super .refresh();
314:            }
315:
316:            protected void updateEnablement() {
317:                boolean useAllPlugins = getTarget().useAllPlugins();
318:                fUseAllPlugins.setSelection(useAllPlugins);
319:                fUseSelectedPlugins.setSelection(!useAllPlugins);
320:                TablePart table = getTablePart();
321:                boolean itemsSelected = !fContentViewer.getSelection()
322:                        .isEmpty();
323:                boolean hasItems = fContentViewer.getTable().getItemCount() > 0;
324:                table.setEnabled(!useAllPlugins);
325:                table.setButtonEnabled(0, isEditable() && !useAllPlugins);
326:                table.setButtonEnabled(1, isEditable() && !useAllPlugins
327:                        && itemsSelected);
328:                table.setButtonEnabled(2, isEditable() && !useAllPlugins
329:                        && hasItems);
330:                boolean pluginTab = (fLastTab == 0);
331:                table.setButtonEnabled(3, isEditable() && pluginTab
332:                        && !useAllPlugins);
333:                table.setButtonEnabled(4, isEditable() && pluginTab
334:                        && !useAllPlugins && hasItems);
335:            }
336:
337:            protected boolean canPaste(Object target, Object[] objects) {
338:                for (int i = 0; i < objects.length; i++) {
339:                    if (objects[i] instanceof  ITargetPlugin && fLastTab == 0
340:                            || objects[i] instanceof  ITargetFeature
341:                            && fLastTab == 1)
342:                        return true;
343:                }
344:                return false;
345:            }
346:
347:            private ITarget getTarget() {
348:                return getModel().getTarget();
349:            }
350:
351:            private ITargetModel getModel() {
352:                return (ITargetModel) getPage().getPDEEditor()
353:                        .getAggregateModel();
354:            }
355:
356:            private void handleAdd() {
357:                if (fLastTab == 0)
358:                    handleAddPlugin();
359:                else
360:                    handleAddFeature();
361:                updateEnablement();
362:            }
363:
364:            private void handleAddPlugin() {
365:                ConditionalListSelectionDialog dialog = new ConditionalListSelectionDialog(
366:                        PDEPlugin.getActiveWorkbenchShell(), PDEPlugin
367:                                .getDefault().getLabelProvider(),
368:                        PDEUIMessages.ContentSection_addDialogButtonLabel);
369:
370:                TreeMap map = getBundles();
371:                dialog.setElements(map.values().toArray());
372:                dialog.setConditionalElements(getWorkspaceBundles(map).values()
373:                        .toArray());
374:                dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
375:                dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
376:                dialog.setMultipleSelection(true);
377:                if (dialog.open() == Window.OK) {
378:                    Object[] bundles = dialog.getResult();
379:                    ITarget target = getTarget();
380:                    ITargetModelFactory factory = getModel().getFactory();
381:                    ITargetPlugin[] plugins = new ITargetPlugin[bundles.length];
382:                    for (int i = 0; i < bundles.length; i++) {
383:                        String id = ((BundleDescription) bundles[i])
384:                                .getSymbolicName();
385:                        ITargetPlugin plugin = factory.createPlugin();
386:                        plugin.setId(id);
387:                        plugins[i] = plugin;
388:                    }
389:                    target.addPlugins(plugins);
390:                    fContentViewer.setSelection(new StructuredSelection(
391:                            plugins[plugins.length - 1]));
392:                }
393:            }
394:
395:            private TreeMap getBundles() {
396:                TreeMap map = new TreeMap();
397:                ITarget target = getTarget();
398:                IPluginModelBase[] models = PluginRegistry.getExternalModels();
399:                for (int i = 0; i < models.length; i++) {
400:                    BundleDescription desc = ((ExternalPluginModelBase) models[i])
401:                            .getBundleDescription();
402:                    String id = desc.getSymbolicName();
403:                    if (!target.containsPlugin(id))
404:                        map.put(id, desc);
405:                }
406:                return map;
407:            }
408:
409:            protected TreeMap getWorkspaceBundles(TreeMap used) {
410:                TreeMap map = new TreeMap();
411:                ITarget target = getTarget();
412:                IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
413:                for (int i = 0; i < models.length; i++) {
414:                    BundleDescription desc = models[i].getBundleDescription();
415:                    String id = desc.getSymbolicName();
416:                    if (id != null && !target.containsPlugin(id)
417:                            && !used.containsKey(id))
418:                        map.put(id, desc);
419:                }
420:                return map;
421:            }
422:
423:            private void handleAddFeature() {
424:                IFeatureModel[] allModels = PDECore.getDefault()
425:                        .getFeatureModelManager().getModels();
426:                ArrayList newModels = new ArrayList();
427:                ITarget target = getTarget();
428:                for (int i = 0; i < allModels.length; i++) {
429:                    if (!target.containsFeature(allModels[i].getFeature()
430:                            .getId()))
431:                        newModels.add(allModels[i]);
432:                }
433:                IFeatureModel[] candidateModels = (IFeatureModel[]) newModels
434:                        .toArray(new IFeatureModel[newModels.size()]);
435:                FeatureSelectionDialog dialog = new FeatureSelectionDialog(
436:                        getSection().getShell(), candidateModels, true);
437:                if (dialog.open() == Window.OK) {
438:                    Object[] models = dialog.getResult();
439:                    ITargetModelFactory factory = getModel().getFactory();
440:                    ITargetFeature[] features = new ITargetFeature[models.length];
441:                    for (int i = 0; i < models.length; ++i) {
442:                        IFeature feature = ((IFeatureModel) models[i])
443:                                .getFeature();
444:                        String id = feature.getId();
445:                        ITargetFeature tfeature = factory.createFeature();
446:                        tfeature.setId(id);
447:                        features[i] = tfeature;
448:                    }
449:                    target.addFeatures(features);
450:                    fContentViewer.setSelection(new StructuredSelection(
451:                            features[features.length - 1]));
452:                }
453:            }
454:
455:            private void handleDelete() {
456:                IStructuredSelection ssel = (IStructuredSelection) fContentViewer
457:                        .getSelection();
458:                if (ssel.size() > 0) {
459:                    Object[] objects = ssel.toArray();
460:                    ITarget target = getTarget();
461:                    if (fLastTab == 0) {
462:                        ITargetPlugin[] plugins = new ITargetPlugin[objects.length];
463:                        System
464:                                .arraycopy(objects, 0, plugins, 0,
465:                                        objects.length);
466:                        target.removePlugins(plugins);
467:                    } else {
468:                        ITargetFeature[] features = new ITargetFeature[objects.length];
469:                        System.arraycopy(objects, 0, features, 0,
470:                                objects.length);
471:                        target.removeFeatures(features);
472:                    }
473:                }
474:                updateEnablement();
475:            }
476:
477:            private void handleRemoveAll() {
478:                TableItem[] items = fContentViewer.getTable().getItems();
479:                ITarget target = getTarget();
480:                if (fLastTab == 0) {
481:                    ITargetPlugin[] plugins = new ITargetPlugin[items.length];
482:                    for (int i = 0; i < plugins.length; i++)
483:                        plugins[i] = (ITargetPlugin) items[i].getData();
484:                    target.removePlugins(plugins);
485:                } else {
486:                    ITargetFeature[] features = new ITargetFeature[items.length];
487:                    for (int i = 0; i < features.length; i++)
488:                        features[i] = (ITargetFeature) items[i].getData();
489:                    target.removeFeatures(features);
490:                }
491:                updateEnablement();
492:            }
493:
494:            /* (non-Javadoc)
495:             * @see org.eclipse.pde.internal.ui.editor.TableSection#handleDoubleClick(org.eclipse.jface.viewers.IStructuredSelection)
496:             */
497:            protected void handleDoubleClick(IStructuredSelection selection) {
498:                handleOpen(selection);
499:            }
500:
501:            private void handleOpen(IStructuredSelection selection) {
502:                Object object = selection.getFirstElement();
503:                if (object instanceof  ITargetPlugin) {
504:                    ManifestEditor.openPluginEditor(((ITargetPlugin) object)
505:                            .getId());
506:                } else if (object instanceof  ITargetFeature) {
507:                    handleOpenFeature((ITargetFeature) object);
508:                }
509:            }
510:
511:            private void handleOpenFeature(ITargetFeature feature) {
512:                IFeatureModel model = PDECore.getDefault()
513:                        .getFeatureModelManager().findFeatureModel(
514:                                feature.getId());
515:                FeatureEditor.openFeatureEditor(model);
516:            }
517:
518:            private void handleAddWorkingSet() {
519:                IWorkingSetManager manager = PlatformUI.getWorkbench()
520:                        .getWorkingSetManager();
521:                IWorkingSetSelectionDialog dialog = manager
522:                        .createWorkingSetSelectionDialog(PDEPlugin
523:                                .getActiveWorkbenchShell(), true);
524:                if (dialog.open() == Window.OK) {
525:                    IWorkingSet[] workingSets = dialog.getSelection();
526:                    ITarget target = getTarget();
527:                    ITargetModelFactory factory = target.getModel()
528:                            .getFactory();
529:                    HashSet plugins = new HashSet();
530:                    for (int i = 0; i < workingSets.length; i++) {
531:                        IAdaptable[] elements = workingSets[i].getElements();
532:                        for (int j = 0; j < elements.length; j++) {
533:                            IPluginModelBase model = findModel(elements[j]);
534:                            if (model != null) {
535:                                ITargetPlugin plugin = factory.createPlugin();
536:                                plugin.setId(model.getPluginBase().getId());
537:                                plugins.add(plugin);
538:                            }
539:                        }
540:                    }
541:                    target.addPlugins((ITargetPlugin[]) plugins
542:                            .toArray(new ITargetPlugin[plugins.size()]));
543:                }
544:                updateEnablement();
545:            }
546:
547:            private IPluginModelBase findModel(IAdaptable object) {
548:                if (object instanceof  IJavaProject)
549:                    object = ((IJavaProject) object).getProject();
550:                if (object instanceof  IProject)
551:                    return PluginRegistry.findModel((IProject) object);
552:                if (object instanceof  PersistablePluginObject) {
553:                    return PluginRegistry
554:                            .findModel(((PersistablePluginObject) object)
555:                                    .getPluginID());
556:                }
557:                return null;
558:            }
559:
560:            public static void handleAddRequired(ITargetPlugin[] plugins,
561:                    boolean includeOptional) {
562:                if (plugins.length == 0)
563:                    return;
564:
565:                ArrayList list = new ArrayList(plugins.length);
566:                for (int i = 0; i < plugins.length; i++) {
567:                    list.add(TargetPlatformHelper.getState().getBundle(
568:                            plugins[i].getId(), null));
569:                }
570:                DependencyCalculator calculator = new DependencyCalculator(
571:                        includeOptional);
572:                calculator.findDependencies(list.toArray());
573:                Collection dependencies = calculator.getBundleIDs();
574:
575:                ITarget target = plugins[0].getTarget();
576:                ITargetModelFactory factory = target.getModel().getFactory();
577:                ITargetPlugin[] pluginsToAdd = new ITargetPlugin[dependencies
578:                        .size()];
579:                int i = 0;
580:                Iterator iter = dependencies.iterator();
581:                while (iter.hasNext()) {
582:                    String id = iter.next().toString();
583:                    ITargetPlugin plugin = factory.createPlugin();
584:                    plugin.setId(id);
585:                    pluginsToAdd[i++] = plugin;
586:                }
587:                target.addPlugins(pluginsToAdd);
588:            }
589:
590:            /* (non-Javadoc)
591:             * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
592:             */
593:            public void modelChanged(IModelChangedEvent e) {
594:                if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
595:                    handleModelEventWorldChanged(e);
596:                    return;
597:                }
598:                Object[] objects = e.getChangedObjects();
599:                if (e.getChangeType() == IModelChangedEvent.INSERT) {
600:                    for (int i = 0; i < objects.length; i++) {
601:                        if ((objects[i] instanceof  ITargetPlugin && fLastTab == 0)
602:                                || (objects[i] instanceof  ITargetFeature && fLastTab == 1)) {
603:                            fContentViewer.add(objects[i]);
604:                        }
605:                    }
606:                } else if (e.getChangeType() == IModelChangedEvent.REMOVE) {
607:
608:                    Table table = fContentViewer.getTable();
609:                    int index = table.getSelectionIndex();
610:
611:                    for (int i = 0; i < objects.length; i++) {
612:                        if ((objects[i] instanceof  ITargetPlugin && fLastTab == 0)
613:                                || (objects[i] instanceof  ITargetFeature && fLastTab == 1)) {
614:                            fContentViewer.remove(objects[i]);
615:                        }
616:                    }
617:
618:                    // Update Selection
619:
620:                    int count = table.getItemCount();
621:
622:                    if (count == 0) {
623:                        // Nothing to select
624:                    } else if (index < count) {
625:                        table.setSelection(index);
626:                    } else {
627:                        table.setSelection(count - 1);
628:                    }
629:
630:                }
631:                if (e.getChangedProperty() == ITarget.P_ALL_PLUGINS) {
632:                    refresh();
633:                    fIncludeOptionalButton.setEnabled(!((Boolean) e
634:                            .getNewValue()).booleanValue());
635:                }
636:            }
637:
638:            /**
639:             * @param event
640:             */
641:            private void handleModelEventWorldChanged(IModelChangedEvent event) {
642:                // Reload input
643:                fContentViewer.setInput(PDECore.getDefault().getModelManager());
644:                // Perform the refresh
645:                refresh();
646:            }
647:
648:            public boolean doGlobalAction(String actionId) {
649:                if (actionId.equals(ActionFactory.DELETE.getId())) {
650:                    handleDelete();
651:                    return true;
652:                }
653:                if (actionId.equals(ActionFactory.CUT.getId())) {
654:                    handleDelete();
655:                    return false;
656:                }
657:                if (actionId.equals(ActionFactory.PASTE.getId())) {
658:                    doPaste();
659:                    return true;
660:                }
661:                if (actionId.equals(ActionFactory.SELECT_ALL.getId())) {
662:                    handleSelectAll();
663:                    return true;
664:                }
665:                return false;
666:            }
667:
668:            private void handleSelectAll() {
669:                fContentViewer.getTable().selectAll();
670:            }
671:
672:            /* (non-Javadoc)
673:             * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#fillContextMenu(org.eclipse.jface.action.IMenuManager)
674:             */
675:            protected void fillContextMenu(IMenuManager manager) {
676:                IStructuredSelection ssel = (IStructuredSelection) fContentViewer
677:                        .getSelection();
678:                if (ssel == null)
679:                    return;
680:
681:                Action openAction = new Action(
682:                        PDEUIMessages.ContentSection_open) {
683:                    public void run() {
684:                        handleDoubleClick((IStructuredSelection) fContentViewer
685:                                .getSelection());
686:                    }
687:                };
688:                openAction.setEnabled(isEditable() && ssel.size() == 1);
689:                manager.add(openAction);
690:
691:                manager.add(new Separator());
692:
693:                Action removeAction = new Action(
694:                        PDEUIMessages.ContentSection_remove) {
695:                    public void run() {
696:                        handleDelete();
697:                    }
698:                };
699:                removeAction.setEnabled(isEditable() && ssel.size() > 0);
700:                manager.add(removeAction);
701:
702:                Action removeAll = new Action(
703:                        PDEUIMessages.ContentSection_removeAll) {
704:                    public void run() {
705:                        handleRemoveAll();
706:                    }
707:                };
708:                removeAll.setEnabled(isEditable());
709:                manager.add(removeAll);
710:
711:                manager.add(new Separator());
712:
713:                getPage().getPDEEditor().getContributor()
714:                        .contextMenuAboutToShow(manager);
715:            }
716:
717:            protected void doPaste(Object target, Object[] objects) {
718:                for (int i = 0; i < objects.length; i++) {
719:                    if (objects[i] instanceof  ITargetPlugin && fLastTab == 0)
720:                        getTarget().addPlugin((ITargetPlugin) objects[i]);
721:                    else if (objects[i] instanceof  ITargetFeature
722:                            && fLastTab == 1)
723:                        getTarget().addFeature((ITargetFeature) objects[i]);
724:                }
725:            }
726:
727:            protected void selectionChanged(IStructuredSelection selection) {
728:                getPage().getPDEEditor().setSelection(selection);
729:            }
730:
731:            public boolean setFormInput(Object input) {
732:                if (input instanceof  ITargetPlugin) {
733:                    if (fTabFolder.getSelectionIndex() != 0) {
734:                        fTabFolder.setSelection(0);
735:                        refresh();
736:                    }
737:                    fContentViewer.setSelection(new StructuredSelection(input),
738:                            true);
739:                    return true;
740:                } else if (input instanceof  ITargetFeature) {
741:                    if (fTabFolder.getSelectionIndex() != 1) {
742:                        fTabFolder.setSelection(1);
743:                        refresh();
744:                    }
745:                    fContentViewer.setSelection(new StructuredSelection(input),
746:                            true);
747:                    return true;
748:                }
749:                return super .setFormInput(input);
750:            }
751:
752:            public void dispose() {
753:                ITargetModel model = getModel();
754:                if (model != null)
755:                    model.removeModelChangedListener(this );
756:                if (fTabImages != null)
757:                    for (int i = 0; i < fTabImages.length; i++)
758:                        fTabImages[i].dispose();
759:                super .dispose();
760:            }
761:
762:            protected boolean createCount() {
763:                return true;
764:            }
765:        }
w__w__w_.j__ava_2_s_.c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.