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


0001:        /*******************************************************************************
0002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
0003:         * All rights reserved. This program and the accompanying materials
0004:         * are made available under the terms of the Eclipse Public License v1.0
0005:         * which accompanies this distribution, and is available at
0006:         * http://www.eclipse.org/legal/epl-v10.html
0007:         *
0008:         * Contributors:
0009:         *     IBM Corporation - initial API and implementation
0010:         *******************************************************************************/package org.eclipse.pde.internal.ui.views.plugins;
0011:
0012:        import java.io.File;
0013:        import java.io.FileInputStream;
0014:        import java.io.FileOutputStream;
0015:        import java.io.IOException;
0016:        import java.util.ArrayList;
0017:        import java.util.Iterator;
0018:        import java.util.Locale;
0019:        import java.util.Set;
0020:
0021:        import org.eclipse.core.resources.IStorage;
0022:        import org.eclipse.core.runtime.CoreException;
0023:        import org.eclipse.core.runtime.IConfigurationElement;
0024:        import org.eclipse.jdt.core.IClassFile;
0025:        import org.eclipse.jdt.core.IJarEntryResource;
0026:        import org.eclipse.jdt.core.IPackageFragment;
0027:        import org.eclipse.jdt.core.JavaModelException;
0028:        import org.eclipse.jdt.ui.JavaUI;
0029:        import org.eclipse.jdt.ui.actions.OpenAction;
0030:        import org.eclipse.jface.action.Action;
0031:        import org.eclipse.jface.action.IMenuListener;
0032:        import org.eclipse.jface.action.IMenuManager;
0033:        import org.eclipse.jface.action.IToolBarManager;
0034:        import org.eclipse.jface.action.MenuManager;
0035:        import org.eclipse.jface.action.Separator;
0036:        import org.eclipse.jface.dialogs.IDialogSettings;
0037:        import org.eclipse.jface.resource.ImageDescriptor;
0038:        import org.eclipse.jface.util.IPropertyChangeListener;
0039:        import org.eclipse.jface.util.PropertyChangeEvent;
0040:        import org.eclipse.jface.viewers.DoubleClickEvent;
0041:        import org.eclipse.jface.viewers.IDoubleClickListener;
0042:        import org.eclipse.jface.viewers.ISelection;
0043:        import org.eclipse.jface.viewers.ISelectionChangedListener;
0044:        import org.eclipse.jface.viewers.IStructuredSelection;
0045:        import org.eclipse.jface.viewers.LabelProvider;
0046:        import org.eclipse.jface.viewers.SelectionChangedEvent;
0047:        import org.eclipse.jface.viewers.StructuredSelection;
0048:        import org.eclipse.jface.viewers.TreeViewer;
0049:        import org.eclipse.jface.viewers.Viewer;
0050:        import org.eclipse.jface.viewers.ViewerFilter;
0051:        import org.eclipse.osgi.util.NLS;
0052:        import org.eclipse.pde.core.plugin.IPluginModelBase;
0053:        import org.eclipse.pde.core.plugin.ModelEntry;
0054:        import org.eclipse.pde.core.plugin.PluginRegistry;
0055:        import org.eclipse.pde.internal.core.DependencyManager;
0056:        import org.eclipse.pde.internal.core.FileAdapter;
0057:        import org.eclipse.pde.internal.core.IPluginModelListener;
0058:        import org.eclipse.pde.internal.core.ModelFileAdapter;
0059:        import org.eclipse.pde.internal.core.PDECore;
0060:        import org.eclipse.pde.internal.core.PluginModelDelta;
0061:        import org.eclipse.pde.internal.core.PluginModelManager;
0062:        import org.eclipse.pde.internal.ui.IHelpContextIds;
0063:        import org.eclipse.pde.internal.ui.IPDEUIConstants;
0064:        import org.eclipse.pde.internal.ui.IPreferenceConstants;
0065:        import org.eclipse.pde.internal.ui.PDEPlugin;
0066:        import org.eclipse.pde.internal.ui.PDEPluginImages;
0067:        import org.eclipse.pde.internal.ui.PDEUIMessages;
0068:        import org.eclipse.pde.internal.ui.editor.JarEntryEditorInput;
0069:        import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
0070:        import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
0071:        import org.eclipse.pde.internal.ui.refactoring.RenamePluginAction;
0072:        import org.eclipse.pde.internal.ui.views.dependencies.OpenPluginDependenciesAction;
0073:        import org.eclipse.pde.internal.ui.views.dependencies.OpenPluginReferencesAction;
0074:        import org.eclipse.pde.internal.ui.wizards.ListUtil;
0075:        import org.eclipse.swt.SWT;
0076:        import org.eclipse.swt.custom.BusyIndicator;
0077:        import org.eclipse.swt.dnd.Clipboard;
0078:        import org.eclipse.swt.dnd.DND;
0079:        import org.eclipse.swt.dnd.FileTransfer;
0080:        import org.eclipse.swt.dnd.Transfer;
0081:        import org.eclipse.swt.program.Program;
0082:        import org.eclipse.swt.widgets.Composite;
0083:        import org.eclipse.swt.widgets.Display;
0084:        import org.eclipse.swt.widgets.Menu;
0085:        import org.eclipse.ui.IActionBars;
0086:        import org.eclipse.ui.IEditorInput;
0087:        import org.eclipse.ui.IPageLayout;
0088:        import org.eclipse.ui.ISharedImages;
0089:        import org.eclipse.ui.IWorkbenchActionConstants;
0090:        import org.eclipse.ui.IWorkbenchPage;
0091:        import org.eclipse.ui.PartInitException;
0092:        import org.eclipse.ui.PlatformUI;
0093:        import org.eclipse.ui.actions.ActionContext;
0094:        import org.eclipse.ui.actions.ActionFactory;
0095:        import org.eclipse.ui.actions.ContributionItemFactory;
0096:        import org.eclipse.ui.keys.IBindingService;
0097:        import org.eclipse.ui.part.DrillDownAdapter;
0098:        import org.eclipse.ui.part.IShowInSource;
0099:        import org.eclipse.ui.part.IShowInTargetList;
0100:        import org.eclipse.ui.part.ShowInContext;
0101:        import org.eclipse.ui.part.ViewPart;
0102:
0103:        public class PluginsView extends ViewPart implements 
0104:                IPluginModelListener {
0105:
0106:            private static final String DEFAULT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
0107:            private static final String HIDE_WRKSPC = "hideWorkspace"; //$NON-NLS-1$
0108:            private static final String HIDE_EXENABLED = "hideEnabledExternal"; //$NON-NLS-1$
0109:            private static final String SHOW_EXDISABLED = "showDisabledExternal"; //$NON-NLS-1$
0110:            private TreeViewer fTreeViewer;
0111:            private DrillDownAdapter fDrillDownAdapter;
0112:            private IPropertyChangeListener fPropertyListener;
0113:            private Action fOpenAction;
0114:            private Action fHideExtDisabledFilterAction;
0115:            private Action fHideExtEnabledFilterAction;
0116:            private Action fHideWorkspaceFilterAction;
0117:            private Action fOpenManifestAction;
0118:            private Action fOpenSchemaAction;
0119:            private Action fOpenSystemEditorAction;
0120:            private Action fOpenClassFileAction;
0121:            private Action fOpenTextEditorAction;
0122:            private Action fSelectDependentAction;
0123:            private Action fSelectInJavaSearchAction;
0124:            private Action fSelectAllAction;
0125:            private RenamePluginAction fRefactorAction;
0126:            private CollapseAllAction fCollapseAllAction;
0127:            private DisabledFilter fHideExtEnabledFilter = new DisabledFilter(
0128:                    true);
0129:            private DisabledFilter fHideExtDisabledFilter = new DisabledFilter(
0130:                    false);
0131:            private WorkspaceFilter fHideWorkspaceFilter = new WorkspaceFilter();
0132:            private JavaFilter fJavaFilter = new JavaFilter();
0133:            private CopyToClipboardAction fCopyAction;
0134:            private Clipboard fClipboard;
0135:            private PluginModelManager fManager;
0136:
0137:            class DisabledFilter extends ViewerFilter {
0138:
0139:                boolean fEnabled;
0140:
0141:                DisabledFilter(boolean enabled) {
0142:                    fEnabled = enabled;
0143:                }
0144:
0145:                public boolean select(Viewer v, Object parent, Object element) {
0146:                    if (element instanceof  IPluginModelBase) {
0147:                        IPluginModelBase model = (IPluginModelBase) element;
0148:                        return model.getUnderlyingResource() != null
0149:                                || model.isEnabled() != fEnabled;
0150:                    }
0151:                    return true;
0152:                }
0153:            }
0154:
0155:            class WorkspaceFilter extends ViewerFilter {
0156:                public boolean select(Viewer v, Object parent, Object element) {
0157:                    if (element instanceof  IPluginModelBase) {
0158:                        IPluginModelBase model = (IPluginModelBase) element;
0159:                        return model.getUnderlyingResource() == null;
0160:                    }
0161:                    return true;
0162:                }
0163:            }
0164:
0165:            class JavaFilter extends ViewerFilter {
0166:                public boolean select(Viewer v, Object parent, Object element) {
0167:                    if (element instanceof  IPackageFragment) {
0168:                        IPackageFragment packageFragment = (IPackageFragment) element;
0169:                        try {
0170:                            return packageFragment.hasChildren();
0171:                        } catch (JavaModelException e) {
0172:                            return false;
0173:                        }
0174:                    }
0175:                    return true;
0176:                }
0177:            }
0178:
0179:            class CollapseAllAction extends Action {
0180:                public CollapseAllAction() {
0181:                    setText(PDEUIMessages.PluginsView_CollapseAllAction_label);
0182:                    setDescription(PDEUIMessages.PluginsView_CollapseAllAction_description);
0183:                    setToolTipText(PDEUIMessages.PluginsView_CollapseAllAction_tooltip);
0184:                    setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL);
0185:                }
0186:
0187:                /*
0188:                 * (non-Javadoc)
0189:                 * 
0190:                 * @see org.eclipse.jface.action.Action#run()
0191:                 */
0192:                public void run() {
0193:                    fTreeViewer.collapseAll();
0194:                }
0195:            }
0196:
0197:            /**
0198:             * Constructor for PluginsView.
0199:             */
0200:            public PluginsView() {
0201:                fPropertyListener = new IPropertyChangeListener() {
0202:                    public void propertyChange(PropertyChangeEvent event) {
0203:                        String property = event.getProperty();
0204:                        if (property
0205:                                .equals(IPreferenceConstants.PROP_SHOW_OBJECTS)) {
0206:                            fTreeViewer.refresh();
0207:                        }
0208:                    }
0209:                };
0210:            }
0211:
0212:            public void dispose() {
0213:                fManager.removePluginModelListener(this );
0214:                PDECore.getDefault().getSearchablePluginsManager()
0215:                        .removePluginModelListener(this );
0216:                PDEPlugin.getDefault().getPreferenceStore()
0217:                        .removePropertyChangeListener(fPropertyListener);
0218:                if (fClipboard != null) {
0219:                    fClipboard.dispose();
0220:                    fClipboard = null;
0221:                }
0222:                super .dispose();
0223:            }
0224:
0225:            /*
0226:             * (non-Javadoc)
0227:             * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
0228:             */
0229:            public void createPartControl(Composite parent) {
0230:                fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.V_SCROLL
0231:                        | SWT.H_SCROLL);
0232:                fDrillDownAdapter = new DrillDownAdapter(fTreeViewer);
0233:                fTreeViewer
0234:                        .setContentProvider(new PluginsContentProvider(this ));
0235:                fTreeViewer.setLabelProvider(new PluginsLabelProvider());
0236:                fTreeViewer.setComparator(ListUtil.PLUGIN_COMPARATOR);
0237:                initDragAndDrop();
0238:                makeActions();
0239:                initFilters();
0240:                IActionBars actionBars = getViewSite().getActionBars();
0241:                contributeToActionBars(actionBars);
0242:                registerGlobalActions(actionBars);
0243:                hookContextMenu();
0244:                hookDoubleClickAction();
0245:                fTreeViewer
0246:                        .addSelectionChangedListener(new ISelectionChangedListener() {
0247:                            public void selectionChanged(SelectionChangedEvent e) {
0248:                                handleSelectionChanged(e.getSelection());
0249:                            }
0250:                        });
0251:                PDECore.getDefault().getSearchablePluginsManager()
0252:                        .addPluginModelListener(this );
0253:                fManager = PDECore.getDefault().getModelManager();
0254:                fTreeViewer.setInput(fManager);
0255:                fManager.addPluginModelListener(this );
0256:                updateContentDescription();
0257:                PDEPlugin.getDefault().getPreferenceStore()
0258:                        .addPropertyChangeListener(fPropertyListener);
0259:                getViewSite().setSelectionProvider(fTreeViewer);
0260:
0261:                PlatformUI.getWorkbench().getHelpSystem().setHelp(
0262:                        fTreeViewer.getControl(), IHelpContextIds.PLUGINS_VIEW);
0263:            }
0264:
0265:            private void contributeToActionBars(IActionBars actionBars) {
0266:                contributeToLocalToolBar(actionBars.getToolBarManager());
0267:                contributeToDropDownMenu(actionBars.getMenuManager());
0268:            }
0269:
0270:            private void contributeToDropDownMenu(IMenuManager manager) {
0271:                manager.add(fHideWorkspaceFilterAction);
0272:                manager.add(fHideExtEnabledFilterAction);
0273:                manager.add(fHideExtDisabledFilterAction);
0274:            }
0275:
0276:            private void contributeToLocalToolBar(IToolBarManager manager) {
0277:                fDrillDownAdapter.addNavigationActions(manager);
0278:                manager.add(new Separator());
0279:                manager.add(fCollapseAllAction);
0280:            }
0281:
0282:            private void registerGlobalActions(IActionBars actionBars) {
0283:                actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL
0284:                        .getId(), fSelectAllAction);
0285:                actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(),
0286:                        new Action() {
0287:                            public void run() {
0288:                                IStructuredSelection selection = (IStructuredSelection) fTreeViewer
0289:                                        .getSelection();
0290:                                if (selection.size() == 1) {
0291:                                    Object element = selection
0292:                                            .getFirstElement();
0293:                                    if (element instanceof  IPluginModelBase) {
0294:                                        fRefactorAction
0295:                                                .setPlugin((IPluginModelBase) element);
0296:                                        fRefactorAction.run();
0297:                                        return;
0298:                                    }
0299:                                }
0300:                                Display.getDefault().beep();
0301:                            }
0302:                        });
0303:            }
0304:
0305:            private void makeActions() {
0306:                fClipboard = new Clipboard(fTreeViewer.getTree().getDisplay());
0307:                fOpenAction = new Action() {
0308:                    public void run() {
0309:                        handleDoubleClick();
0310:                    }
0311:                };
0312:                fOpenAction.setText(PDEUIMessages.PluginsView_open);
0313:
0314:                fHideExtDisabledFilterAction = new Action() {
0315:                    public void run() {
0316:                        boolean checked = fHideExtDisabledFilterAction
0317:                                .isChecked();
0318:                        if (checked)
0319:                            fTreeViewer.removeFilter(fHideExtDisabledFilter);
0320:                        else
0321:                            fTreeViewer.addFilter(fHideExtDisabledFilter);
0322:                        getSettings().put(SHOW_EXDISABLED, checked);
0323:                        updateContentDescription();
0324:                    }
0325:                };
0326:                fHideExtDisabledFilterAction
0327:                        .setText(PDEUIMessages.PluginsView_showDisabled);
0328:
0329:                fHideExtEnabledFilterAction = new Action() {
0330:                    public void run() {
0331:                        boolean checked = fHideExtEnabledFilterAction
0332:                                .isChecked();
0333:                        if (checked)
0334:                            fTreeViewer.removeFilter(fHideExtEnabledFilter);
0335:                        else
0336:                            fTreeViewer.addFilter(fHideExtEnabledFilter);
0337:                        getSettings().put(HIDE_EXENABLED, !checked);
0338:                        updateContentDescription();
0339:                    }
0340:                };
0341:                fHideExtEnabledFilterAction
0342:                        .setText(PDEUIMessages.PluginsView_showEnabled);
0343:
0344:                fHideWorkspaceFilterAction = new Action() {
0345:                    public void run() {
0346:                        boolean checked = fHideWorkspaceFilterAction
0347:                                .isChecked();
0348:                        if (checked)
0349:                            fTreeViewer.removeFilter(fHideWorkspaceFilter);
0350:                        else
0351:                            fTreeViewer.addFilter(fHideWorkspaceFilter);
0352:                        getSettings().put(HIDE_WRKSPC, !checked);
0353:                        updateContentDescription();
0354:                    }
0355:                };
0356:                fHideWorkspaceFilterAction
0357:                        .setText(PDEUIMessages.PluginsView_showWorkspace);
0358:
0359:                fOpenTextEditorAction = new Action() {
0360:                    public void run() {
0361:                        handleOpenTextEditor(getSelectedFile(), null);
0362:                    }
0363:                };
0364:                fOpenTextEditorAction
0365:                        .setText(PDEUIMessages.PluginsView_textEditor);
0366:                fOpenTextEditorAction.setImageDescriptor(PlatformUI
0367:                        .getWorkbench().getSharedImages().getImageDescriptor(
0368:                                ISharedImages.IMG_OBJ_FILE));
0369:
0370:                fOpenSystemEditorAction = new Action() {
0371:                    public void run() {
0372:                        handleOpenSystemEditor(getSelectedFile());
0373:                    }
0374:                };
0375:                fOpenSystemEditorAction
0376:                        .setText(PDEUIMessages.PluginsView_systemEditor);
0377:
0378:                fOpenManifestAction = new Action() {
0379:                    public void run() {
0380:                        handleOpenManifestEditor(getSelectedFile());
0381:                    }
0382:                };
0383:                fOpenManifestAction
0384:                        .setText(PDEUIMessages.PluginsView_manifestEditor);
0385:
0386:                fOpenSchemaAction = new Action() {
0387:                    public void run() {
0388:                        handleOpenSchemaEditor(getSelectedFile());
0389:                    }
0390:                };
0391:                fOpenSchemaAction
0392:                        .setText(PDEUIMessages.PluginsView_schemaEditor);
0393:
0394:                fCopyAction = new CopyToClipboardAction(fClipboard);
0395:                fCopyAction.setText(PDEUIMessages.PluginsView_copy);
0396:
0397:                fSelectDependentAction = new Action() {
0398:                    public void run() {
0399:                        handleSelectDependencies();
0400:                    }
0401:                };
0402:                fSelectDependentAction
0403:                        .setText(PDEUIMessages.PluginsView_dependentPlugins);
0404:
0405:                fSelectInJavaSearchAction = new Action() {
0406:                    public void run() {
0407:                        handleSelectInJavaSearch();
0408:                    }
0409:                };
0410:                fSelectInJavaSearchAction
0411:                        .setText(PDEUIMessages.PluginsView_pluginsInJavaSearch);
0412:
0413:                fSelectAllAction = new Action() {
0414:                    public void run() {
0415:                        super .run();
0416:                        fTreeViewer.getTree().selectAll();
0417:                    }
0418:                };
0419:                fSelectAllAction
0420:                        .setText(PDEUIMessages.PluginsView_SelectAllAction_label);
0421:
0422:                fCollapseAllAction = new CollapseAllAction();
0423:
0424:                fOpenClassFileAction = new OpenAction(getViewSite());
0425:
0426:                fRefactorAction = new RenamePluginAction();
0427:            }
0428:
0429:            private FileAdapter getSelectedFile() {
0430:                Object obj = getSelectedObject();
0431:                if (obj instanceof  FileAdapter)
0432:                    return (FileAdapter) obj;
0433:                return null;
0434:            }
0435:
0436:            private IPluginModelBase getEnclosingModel() {
0437:                Object obj = getSelectedObject();
0438:                if (obj == null)
0439:                    return null;
0440:                if (obj instanceof  IPluginModelBase)
0441:                    return (IPluginModelBase) obj;
0442:                if (obj instanceof  FileAdapter) {
0443:                    FileAdapter file = (FileAdapter) obj;
0444:                    if (file.isManifest()) {
0445:                        FileAdapter parent = file.getParent();
0446:                        if (parent instanceof  ModelFileAdapter)
0447:                            return ((ModelFileAdapter) parent).getModel();
0448:                    }
0449:                }
0450:                return null;
0451:            }
0452:
0453:            private Object getSelectedObject() {
0454:                IStructuredSelection selection = (IStructuredSelection) fTreeViewer
0455:                        .getSelection();
0456:                if (selection.isEmpty() || selection.size() != 1)
0457:                    return null;
0458:                return selection.getFirstElement();
0459:            }
0460:
0461:            private void fillContextMenu(IMenuManager manager) {
0462:                IStructuredSelection selection = (IStructuredSelection) fTreeViewer
0463:                        .getSelection();
0464:
0465:                boolean allowRefactoring = false;
0466:                if (selection.size() == 1) {
0467:                    Object sobj = selection.getFirstElement();
0468:                    boolean addSeparator = false;
0469:                    if (sobj instanceof  IPluginModelBase) {
0470:                        IPluginModelBase model = (IPluginModelBase) sobj;
0471:                        File file = new File(model.getInstallLocation());
0472:                        if (file.isFile()
0473:                                || model.getUnderlyingResource() != null) {
0474:                            manager.add(fOpenAction);
0475:                        }
0476:                        if (model.getUnderlyingResource() != null)
0477:                            allowRefactoring = true;
0478:                    }
0479:                    if (sobj instanceof  FileAdapter
0480:                            && ((FileAdapter) sobj).isDirectory() == false) {
0481:                        manager.add(fOpenAction);
0482:                        MenuManager openWithMenu = new MenuManager(
0483:                                PDEUIMessages.PluginsView_openWith);
0484:                        fillOpenWithMenu(openWithMenu, sobj);
0485:                        manager.add(openWithMenu);
0486:                        addSeparator = true;
0487:                    }
0488:                    if (isOpenableStorage(sobj)) {
0489:                        manager.add(fOpenAction);
0490:                        addSeparator = true;
0491:                    }
0492:                    if (sobj instanceof  IClassFile) {
0493:                        manager.add(fOpenClassFileAction);
0494:                        addSeparator = true;
0495:                    }
0496:                    IPluginModelBase entry = getEnclosingModel();
0497:                    if (entry != null) {
0498:                        Action action = new OpenPluginDependenciesAction(entry);
0499:                        action
0500:                                .setText(PDEUIMessages.PluginsView_openDependencies);
0501:                        action.setImageDescriptor(PDEPluginImages.DESC_CALLEES);
0502:                        manager.add(action);
0503:                        manager.add(new Separator());
0504:
0505:                        action = new OpenPluginReferencesAction(entry);
0506:                        action.setText(PDEUIMessages.SearchAction_references);
0507:                        action.setImageDescriptor(PDEPluginImages.DESC_CALLERS);
0508:                        manager.add(action);
0509:                        addSeparator = true;
0510:                    }
0511:                    if (addSeparator)
0512:                        manager.add(new Separator());
0513:                }
0514:                if (selection.size() > 0) {
0515:                    if (isShowInApplicable()) {
0516:                        String showInLabel = PDEUIMessages.PluginsView_showIn;
0517:                        IBindingService bindingService = (IBindingService) PlatformUI
0518:                                .getWorkbench().getAdapter(
0519:                                        IBindingService.class);
0520:                        if (bindingService != null) {
0521:                            String keyBinding = bindingService
0522:                                    .getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); //$NON-NLS-1$
0523:                            if (keyBinding != null) {
0524:                                showInLabel += '\t' + keyBinding;
0525:                            }
0526:                        }
0527:                        IMenuManager showInMenu = new MenuManager(showInLabel);
0528:                        showInMenu.add(ContributionItemFactory.VIEWS_SHOW_IN
0529:                                .create(getViewSite().getWorkbenchWindow()));
0530:
0531:                        manager.add(showInMenu);
0532:                        manager.add(new Separator());
0533:                    }
0534:                    if (ImportActionGroup.canImport(selection)) {
0535:                        ImportActionGroup actionGroup = new ImportActionGroup();
0536:                        actionGroup.setContext(new ActionContext(selection));
0537:                        actionGroup.fillContextMenu(manager);
0538:                        manager.add(new Separator());
0539:                    }
0540:
0541:                    JavaSearchActionGroup actionGroup = new JavaSearchActionGroup();
0542:                    actionGroup.setContext(new ActionContext(selection));
0543:                    actionGroup.fillContextMenu(manager);
0544:                }
0545:                fCopyAction.setSelection(selection);
0546:                manager.add(fCopyAction);
0547:                IMenuManager selectionMenu = new MenuManager(
0548:                        PDEUIMessages.PluginsView_select);
0549:                manager.add(selectionMenu);
0550:                if (selection.size() > 0)
0551:                    selectionMenu.add(fSelectDependentAction);
0552:                selectionMenu.add(fSelectInJavaSearchAction);
0553:                selectionMenu.add(fSelectAllAction);
0554:                manager.add(new Separator());
0555:                if (allowRefactoring) {
0556:                    fRefactorAction.setPlugin((IPluginModelBase) selection
0557:                            .getFirstElement());
0558:                    manager.add(fRefactorAction);
0559:                    manager.add(new Separator());
0560:                }
0561:                fDrillDownAdapter.addNavigationActions(manager);
0562:                manager.add(new Separator(
0563:                        IWorkbenchActionConstants.MB_ADDITIONS));
0564:            }
0565:
0566:            public boolean isShowInApplicable() {
0567:                IStructuredSelection selection = (IStructuredSelection) fTreeViewer
0568:                        .getSelection();
0569:                if (selection.isEmpty())
0570:                    return false;
0571:                for (Iterator iter = selection.iterator(); iter.hasNext();) {
0572:                    Object obj = iter.next();
0573:                    if (!(obj instanceof  IPluginModelBase))
0574:                        return false;
0575:                    if (((IPluginModelBase) obj).getUnderlyingResource() == null)
0576:                        return false;
0577:                }
0578:                return true;
0579:            }
0580:
0581:            private void fillOpenWithMenu(IMenuManager manager, Object obj) {
0582:                FileAdapter adapter = (FileAdapter) obj;
0583:                String editorId = adapter.getEditorId();
0584:
0585:                String fileName = adapter.getFile().getName();
0586:                String lcFileName = fileName.toLowerCase(Locale.ENGLISH);
0587:                ImageDescriptor desc = PlatformUI.getWorkbench()
0588:                        .getEditorRegistry().getImageDescriptor(fileName);
0589:                if (lcFileName.equals("plugin.xml") //$NON-NLS-1$
0590:                        || lcFileName.equals("fragment.xml") //$NON-NLS-1$
0591:                        || lcFileName.equals("manifest.mf")) { //$NON-NLS-1$
0592:                    fOpenManifestAction.setImageDescriptor(desc);
0593:                    manager.add(fOpenManifestAction);
0594:                    manager.add(new Separator());
0595:                    fOpenManifestAction
0596:                            .setChecked(editorId != null
0597:                                    && editorId
0598:                                            .equals(IPDEUIConstants.MANIFEST_EDITOR_ID));
0599:                }
0600:                if (lcFileName.endsWith(".mxsd") || lcFileName.endsWith(".exsd")) { //$NON-NLS-1$ //$NON-NLS-2$
0601:                    fOpenSchemaAction.setImageDescriptor(desc);
0602:                    manager.add(fOpenSchemaAction);
0603:                    manager.add(new Separator());
0604:                    fOpenSchemaAction.setChecked(editorId != null
0605:                            && editorId
0606:                                    .equals(IPDEUIConstants.SCHEMA_EDITOR_ID));
0607:                }
0608:                manager.add(fOpenTextEditorAction);
0609:                fOpenTextEditorAction.setChecked(editorId == null
0610:                        || editorId.equals(DEFAULT_EDITOR_ID));
0611:                fOpenSystemEditorAction.setImageDescriptor(desc);
0612:                fOpenSystemEditorAction.setChecked(editorId != null
0613:                        && editorId.equals("@system")); //$NON-NLS-1$
0614:                manager.add(fOpenSystemEditorAction);
0615:            }
0616:
0617:            protected void initDragAndDrop() {
0618:                int ops = DND.DROP_COPY | DND.DROP_MOVE;
0619:                Transfer[] transfers = new Transfer[] { FileTransfer
0620:                        .getInstance() };
0621:                fTreeViewer.addDragSupport(ops, transfers,
0622:                        new PluginsDragAdapter(fTreeViewer));
0623:            }
0624:
0625:            private IDialogSettings getSettings() {
0626:                IDialogSettings master = PDEPlugin.getDefault()
0627:                        .getDialogSettings();
0628:                IDialogSettings section = master.getSection("pluginsView"); //$NON-NLS-1$
0629:                if (section == null) {
0630:                    section = master.addNewSection("pluginsView"); //$NON-NLS-1$
0631:                }
0632:                return section;
0633:            }
0634:
0635:            private void initFilters() {
0636:                IDialogSettings settings = getSettings();
0637:                fTreeViewer.addFilter(fJavaFilter);
0638:                boolean hideWorkspace = settings.getBoolean(HIDE_WRKSPC);
0639:                boolean hideEnabledExternal = settings
0640:                        .getBoolean(HIDE_EXENABLED);
0641:                boolean hideDisabledExternal = !settings
0642:                        .getBoolean(SHOW_EXDISABLED);
0643:                if (hideWorkspace)
0644:                    fTreeViewer.addFilter(fHideWorkspaceFilter);
0645:                if (hideEnabledExternal)
0646:                    fTreeViewer.addFilter(fHideExtEnabledFilter);
0647:                if (hideDisabledExternal)
0648:                    fTreeViewer.addFilter(fHideExtDisabledFilter);
0649:                fHideWorkspaceFilterAction.setChecked(!hideWorkspace);
0650:                fHideExtEnabledFilterAction.setChecked(!hideEnabledExternal);
0651:                fHideExtDisabledFilterAction.setChecked(!hideDisabledExternal);
0652:            }
0653:
0654:            private void hookContextMenu() {
0655:                MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
0656:                menuMgr.setRemoveAllWhenShown(true);
0657:                menuMgr.addMenuListener(new IMenuListener() {
0658:                    public void menuAboutToShow(IMenuManager manager) {
0659:                        PluginsView.this .fillContextMenu(manager);
0660:                    }
0661:                });
0662:                Menu menu = menuMgr.createContextMenu(fTreeViewer.getControl());
0663:                fTreeViewer.getControl().setMenu(menu);
0664:                getSite().registerContextMenu(menuMgr, fTreeViewer);
0665:            }
0666:
0667:            private void handleDoubleClick() {
0668:                Object obj = getSelectedObject();
0669:                if (obj instanceof  IPluginModelBase) {
0670:                    boolean expanded = false;
0671:                    // only expand target models
0672:                    if (((IPluginModelBase) obj).getUnderlyingResource() == null) {
0673:                        expanded = fTreeViewer.getExpandedState(obj);
0674:                        fTreeViewer.setExpandedState(obj, !expanded);
0675:                    }
0676:                    if (fTreeViewer.getExpandedState(obj) == expanded) {
0677:                        // not expandable, open editor
0678:                        ManifestEditor.openPluginEditor((IPluginModelBase) obj);
0679:                    }
0680:                } else if (obj instanceof  FileAdapter) {
0681:                    FileAdapter adapter = (FileAdapter) obj;
0682:                    if (adapter.isDirectory()) {
0683:                        fTreeViewer.setExpandedState(adapter, !fTreeViewer
0684:                                .getExpandedState(adapter));
0685:                        return;
0686:                    }
0687:                    String editorId = adapter.getEditorId();
0688:                    if (editorId != null && editorId.equals("@system")) //$NON-NLS-1$
0689:                        handleOpenSystemEditor(adapter);
0690:                    else
0691:                        handleOpenTextEditor(adapter, editorId);
0692:                } else if (obj instanceof  IClassFile) {
0693:                    fOpenClassFileAction.run();
0694:                } else if (isOpenableStorage(obj)) {
0695:                    handleOpenStorage((IStorage) obj);
0696:                }
0697:            }
0698:
0699:            private static boolean isOpenableStorage(Object storage) {
0700:                if (storage instanceof  IJarEntryResource)
0701:                    return ((IJarEntryResource) storage).isFile();
0702:                return storage instanceof  IStorage;
0703:            }
0704:
0705:            private void handleOpenStorage(IStorage obj) {
0706:                IWorkbenchPage page = PDEPlugin.getActivePage();
0707:                IEditorInput input = new JarEntryEditorInput(obj);
0708:                try {
0709:                    page.openEditor(input, DEFAULT_EDITOR_ID);
0710:                } catch (PartInitException e) {
0711:                    PDEPlugin.logException(e);
0712:                }
0713:            }
0714:
0715:            private void handleSelectDependencies() {
0716:                IStructuredSelection selection = (IStructuredSelection) fTreeViewer
0717:                        .getSelection();
0718:                if (selection.size() == 0)
0719:                    return;
0720:
0721:                IPluginModelBase[] models = new IPluginModelBase[selection
0722:                        .size()];
0723:                System.arraycopy(selection.toArray(), 0, models, 0, selection
0724:                        .size());
0725:                Set set = DependencyManager.getSelfandDependencies(models);
0726:                Object[] symbolicNames = set.toArray();
0727:                ArrayList result = new ArrayList(set.size());
0728:                for (int i = 0; i < symbolicNames.length; i++) {
0729:                    IPluginModelBase model = PluginRegistry
0730:                            .findModel(symbolicNames[i].toString());
0731:                    if (model != null)
0732:                        result.add(model);
0733:                }
0734:                fTreeViewer.setSelection(new StructuredSelection(result
0735:                        .toArray()));
0736:            }
0737:
0738:            private void handleSelectInJavaSearch() {
0739:                PluginsContentProvider provider = (PluginsContentProvider) fTreeViewer
0740:                        .getContentProvider();
0741:                Object[] elements = provider
0742:                        .getElements(fTreeViewer.getInput());
0743:                ArrayList result = new ArrayList();
0744:                for (int i = 0; i < elements.length; i++) {
0745:                    Object element = elements[i];
0746:                    if (element instanceof  IPluginModelBase) {
0747:                        String id = ((IPluginModelBase) element)
0748:                                .getPluginBase().getId();
0749:                        if (PDECore.getDefault().getSearchablePluginsManager()
0750:                                .isInJavaSearch(id))
0751:                            result.add(element);
0752:                    }
0753:                }
0754:                fTreeViewer.setSelection(new StructuredSelection(result
0755:                        .toArray()));
0756:            }
0757:
0758:            private void handleOpenTextEditor(FileAdapter adapter,
0759:                    String editorId) {
0760:                if (adapter == null)
0761:                    return;
0762:                IWorkbenchPage page = PDEPlugin.getActivePage();
0763:                if (editorId == null) {
0764:                    if (adapter.isManifest())
0765:                        editorId = IPDEUIConstants.MANIFEST_EDITOR_ID;
0766:                    else if (adapter.isSchema())
0767:                        editorId = IPDEUIConstants.SCHEMA_EDITOR_ID;
0768:                }
0769:                try {
0770:                    if (editorId == null || editorId.equals("@system")) //$NON-NLS-1$
0771:                        editorId = DEFAULT_EDITOR_ID;
0772:                    page.openEditor(
0773:                            new SystemFileEditorInput(adapter.getFile()),
0774:                            editorId);
0775:                    adapter.setEditorId(editorId);
0776:                } catch (PartInitException e) {
0777:                    PDEPlugin.logException(e);
0778:                }
0779:            }
0780:
0781:            private void handleOpenManifestEditor(FileAdapter adapter) {
0782:                handleOpenTextEditor(adapter,
0783:                        IPDEUIConstants.MANIFEST_EDITOR_ID);
0784:            }
0785:
0786:            private void handleOpenSchemaEditor(FileAdapter adapter) {
0787:                handleOpenTextEditor(adapter, IPDEUIConstants.SCHEMA_EDITOR_ID);
0788:            }
0789:
0790:            private void handleOpenSystemEditor(FileAdapter adapter) {
0791:                if (adapter == null)
0792:                    return;
0793:                File localFile = null;
0794:
0795:                try {
0796:                    localFile = getLocalCopy(adapter.getFile());
0797:                } catch (IOException e) {
0798:                    PDEPlugin.logException(e);
0799:                    return;
0800:                } catch (CoreException e) {
0801:                    PDEPlugin.logException(e);
0802:                }
0803:                // Start busy indicator.
0804:                final File file = localFile;
0805:                final boolean result[] = new boolean[1];
0806:                BusyIndicator.showWhile(fTreeViewer.getTree().getDisplay(),
0807:                        new Runnable() {
0808:                            public void run() {
0809:                                // Open file using shell.
0810:                                String path = file.getAbsolutePath();
0811:                                result[0] = Program.launch(path);
0812:                            }
0813:                        });
0814:
0815:                // ShellExecute returns whether call was successful
0816:                if (!result[0]) {
0817:                    PDEPlugin.logException(new PartInitException(NLS.bind(
0818:                            PDEUIMessages.PluginsView_unableToOpen, file
0819:                                    .getName())));
0820:                } else {
0821:                    adapter.setEditorId("@system"); //$NON-NLS-1$
0822:                }
0823:            }
0824:
0825:            private File getLocalCopy(File file) throws IOException,
0826:                    CoreException {
0827:                // create a tmp. copy of this file and make it
0828:                // read-only. This is to ensure that the original
0829:                // file belonging to the external plug-in directories
0830:                // will not be modified. 
0831:                String fileName = file.getName();
0832:                String prefix;
0833:                String suffix = null;
0834:                int dotLoc = fileName.indexOf('.');
0835:                if (dotLoc != -1) {
0836:                    prefix = fileName.substring(0, dotLoc);
0837:                    suffix = fileName.substring(dotLoc);
0838:                } else {
0839:                    prefix = fileName;
0840:                }
0841:
0842:                File tmpFile = File.createTempFile(prefix, suffix);
0843:                tmpFile.deleteOnExit();
0844:                FileOutputStream fos = new FileOutputStream(tmpFile);
0845:                FileInputStream fis = new FileInputStream(file);
0846:                byte[] cbuffer = new byte[1024];
0847:                int read = 0;
0848:
0849:                while (read != -1) {
0850:                    read = fis.read(cbuffer);
0851:                    if (read != -1)
0852:                        fos.write(cbuffer, 0, read);
0853:                }
0854:                fos.flush();
0855:                fos.close();
0856:                fis.close();
0857:                tmpFile.setReadOnly();
0858:                return tmpFile;
0859:            }
0860:
0861:            private void handleSelectionChanged(ISelection selection) {
0862:                String text = ""; //$NON-NLS-1$
0863:                Object obj = getSelectedObject();
0864:                if (obj instanceof  IPluginModelBase) {
0865:                    text = ((IPluginModelBase) obj).getInstallLocation();
0866:                }
0867:                if (obj instanceof  FileAdapter) {
0868:                    text = ((FileAdapter) obj).getFile().getAbsolutePath();
0869:                }
0870:                getViewSite().getActionBars().getStatusLineManager()
0871:                        .setMessage(text);
0872:            }
0873:
0874:            private void hookDoubleClickAction() {
0875:                fTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
0876:                    public void doubleClick(DoubleClickEvent event) {
0877:                        handleDoubleClick();
0878:                    }
0879:                });
0880:            }
0881:
0882:            /*
0883:             * (non-Javadoc)
0884:             * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
0885:             */
0886:            public void setFocus() {
0887:                fTreeViewer.getTree().setFocus();
0888:            }
0889:
0890:            void updateTitle(Object newInput) {
0891:                IConfigurationElement config = getConfigurationElement();
0892:                if (config == null)
0893:                    return;
0894:
0895:                if (newInput == null
0896:                        || newInput.equals(PDECore.getDefault()
0897:                                .getModelManager())) {
0898:                    updateContentDescription();
0899:                    setTitleToolTip(getTitle());
0900:                } else {
0901:                    String viewName = config.getAttribute("name"); //$NON-NLS-1$
0902:                    String name = ((LabelProvider) fTreeViewer
0903:                            .getLabelProvider()).getText(newInput);
0904:                    setContentDescription(viewName + ": " + name); //$NON-NLS-1$
0905:                    setTitleToolTip(getInputPath(newInput));
0906:                }
0907:            }
0908:
0909:            private String getInputPath(Object input) {
0910:                if (input instanceof  FileAdapter) {
0911:                    return "file: " + ((FileAdapter) input).getFile().getAbsolutePath(); //$NON-NLS-1$
0912:                }
0913:                if (input instanceof  IPluginModelBase) {
0914:                    IPluginModelBase model = (IPluginModelBase) input;
0915:                    return "plugin: " + model.getInstallLocation(); //$NON-NLS-1$
0916:                }
0917:                return ""; //$NON-NLS-1$
0918:            }
0919:
0920:            private void updateContentDescription() {
0921:                String total = Integer
0922:                        .toString(PluginRegistry.getAllModels().length);
0923:                String visible = Integer.toString(fTreeViewer.getTree()
0924:                        .getItemCount());
0925:                setContentDescription(NLS.bind(
0926:                        PDEUIMessages.PluginsView_description, visible, total));
0927:            }
0928:
0929:            public void modelsChanged(final PluginModelDelta delta) {
0930:                if (fTreeViewer == null || fTreeViewer.getTree().isDisposed())
0931:                    return;
0932:
0933:                fTreeViewer.getTree().getDisplay().asyncExec(new Runnable() {
0934:                    public void run() {
0935:                        int kind = delta.getKind();
0936:                        if (fTreeViewer.getTree().isDisposed())
0937:                            return;
0938:                        if ((kind & PluginModelDelta.CHANGED) != 0
0939:                                || (kind & PluginModelDelta.REMOVED) != 0) {
0940:                            // Don't know exactly what change - 
0941:                            // the safest way out is to refresh
0942:                            fTreeViewer.refresh();
0943:                        } else if ((kind & PluginModelDelta.ADDED) != 0) {
0944:                            ModelEntry[] added = delta.getAddedEntries();
0945:                            for (int i = 0; i < added.length; i++) {
0946:                                IPluginModelBase[] models = getModels(added[i]);
0947:                                for (int j = 0; j < models.length; j++) {
0948:                                    if (isVisible(models[j]))
0949:                                        fTreeViewer.add(fManager, models[j]);
0950:                                }
0951:                            }
0952:                        }
0953:                        updateContentDescription();
0954:                    }
0955:                });
0956:            }
0957:
0958:            private IPluginModelBase[] getModels(ModelEntry entry) {
0959:                return (entry.hasWorkspaceModels()) ? entry
0960:                        .getWorkspaceModels() : entry.getExternalModels();
0961:            }
0962:
0963:            private boolean isVisible(IPluginModelBase entry) {
0964:                ViewerFilter[] filters = fTreeViewer.getFilters();
0965:                for (int i = 0; i < filters.length; i++) {
0966:                    if (!filters[i].select(fTreeViewer, fManager, entry))
0967:                        return false;
0968:                }
0969:                return true;
0970:            }
0971:
0972:            public Object getAdapter(Class adapter) {
0973:                if (isShowInApplicable()) {
0974:                    if (adapter == IShowInSource.class && isShowInApplicable()) {
0975:                        return getShowInSource();
0976:                    } else if (adapter == IShowInTargetList.class) {
0977:                        return getShowInTargetList();
0978:                    }
0979:                }
0980:
0981:                return super .getAdapter(adapter);
0982:            }
0983:
0984:            /**
0985:             * Returns the <code>IShowInSource</code> for this view.
0986:             * @return the <code>IShowInSource</code> 
0987:             */
0988:            protected IShowInSource getShowInSource() {
0989:                return new IShowInSource() {
0990:                    public ShowInContext getShowInContext() {
0991:                        ArrayList resourceList = new ArrayList();
0992:                        IStructuredSelection selection = (IStructuredSelection) fTreeViewer
0993:                                .getSelection();
0994:                        IStructuredSelection resources;
0995:                        if (selection.isEmpty()) {
0996:                            resources = null;
0997:                        } else {
0998:                            for (Iterator iter = selection.iterator(); iter
0999:                                    .hasNext();) {
1000:                                Object obj = iter.next();
1001:                                if (obj instanceof  IPluginModelBase) {
1002:                                    resourceList.add(((IPluginModelBase) obj)
1003:                                            .getUnderlyingResource());
1004:                                }
1005:                            }
1006:                            resources = new StructuredSelection(resourceList);
1007:                        }
1008:
1009:                        return new ShowInContext(fTreeViewer.getInput(),
1010:                                resources);
1011:                    }
1012:                };
1013:            }
1014:
1015:            /**
1016:             * Returns the <code>IShowInTargetList</code> for this view.
1017:             * @return the <code>IShowInTargetList</code> 
1018:             */
1019:            protected IShowInTargetList getShowInTargetList() {
1020:                return new IShowInTargetList() {
1021:                    public String[] getShowInTargetIds() {
1022:                        return new String[] { JavaUI.ID_PACKAGES,
1023:                                IPageLayout.ID_RES_NAV };
1024:                    }
1025:                };
1026:            }
1027:        }
w_w___w.__j__a___va_2s__._c___o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.