Source Code Cross Referenced for ImplicitDependenciesSection.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:         *******************************************************************************/package org.eclipse.pde.internal.ui.editor.target;
011:
012:        import java.util.ArrayList;
013:        import java.util.HashSet;
014:        import java.util.Set;
015:
016:        import org.eclipse.jface.viewers.ISelectionChangedListener;
017:        import org.eclipse.jface.viewers.IStructuredSelection;
018:        import org.eclipse.jface.viewers.SelectionChangedEvent;
019:        import org.eclipse.jface.viewers.TableViewer;
020:        import org.eclipse.jface.viewers.Viewer;
021:        import org.eclipse.jface.viewers.ViewerComparator;
022:        import org.eclipse.jface.window.Window;
023:        import org.eclipse.osgi.service.resolver.BundleDescription;
024:        import org.eclipse.pde.core.IModelChangedEvent;
025:        import org.eclipse.pde.core.plugin.IPluginModelBase;
026:        import org.eclipse.pde.core.plugin.PluginRegistry;
027:        import org.eclipse.pde.internal.core.itarget.IImplicitDependenciesInfo;
028:        import org.eclipse.pde.internal.core.itarget.ITarget;
029:        import org.eclipse.pde.internal.core.itarget.ITargetModel;
030:        import org.eclipse.pde.internal.core.itarget.ITargetPlugin;
031:        import org.eclipse.pde.internal.ui.PDEPlugin;
032:        import org.eclipse.pde.internal.ui.PDEUIMessages;
033:        import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
034:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
035:        import org.eclipse.pde.internal.ui.editor.TableSection;
036:        import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
037:        import org.eclipse.pde.internal.ui.elements.DefaultTableProvider;
038:        import org.eclipse.pde.internal.ui.parts.TablePart;
039:        import org.eclipse.swt.SWT;
040:        import org.eclipse.swt.layout.GridData;
041:        import org.eclipse.swt.widgets.Composite;
042:        import org.eclipse.ui.actions.ActionFactory;
043:        import org.eclipse.ui.dialogs.ElementListSelectionDialog;
044:        import org.eclipse.ui.forms.widgets.FormToolkit;
045:        import org.eclipse.ui.forms.widgets.Section;
046:
047:        public class ImplicitDependenciesSection extends TableSection {
048:
049:            private TableViewer fViewer;
050:            private static final int ADD_INDEX = 0;
051:            private static final int REMOVE_INDEX = 1;
052:            private static final int REMOVE_ALL_INDEX = 2;
053:
054:            public ImplicitDependenciesSection(PDEFormPage page,
055:                    Composite parent) {
056:                super (page, parent, Section.DESCRIPTION, new String[] {
057:                        PDEUIMessages.ImplicitDependenicesSection_Add,
058:                        PDEUIMessages.ImplicitDependenicesSection_Remove,
059:                        PDEUIMessages.ImplicitDependenicesSection_RemoveAll });
060:            }
061:
062:            protected void createClient(Section section, FormToolkit toolkit) {
063:                section.setLayout(FormLayoutFactory.createClearGridLayout(
064:                        false, 1));
065:                section
066:                        .setText(PDEUIMessages.ImplicitDependenicesSection_Title);
067:                section
068:                        .setDescription(PDEUIMessages.TargetImplicitPluginsTab_desc);
069:                Composite container = toolkit.createComposite(section);
070:                container.setLayout(FormLayoutFactory
071:                        .createSectionClientGridLayout(false, 2));
072:                container.setLayoutData(new GridData(GridData.FILL_BOTH));
073:                createViewerPartControl(container, SWT.MULTI, 2, toolkit);
074:                fViewer = getTablePart().getTableViewer();
075:                fViewer.setContentProvider(new DefaultTableProvider() {
076:                    public Object[] getElements(Object inputElement) {
077:                        return getImplicitPluginsInfo().getPlugins();
078:                    }
079:                });
080:                fViewer.setLabelProvider(PDEPlugin.getDefault()
081:                        .getLabelProvider());
082:                fViewer.setComparator(new ViewerComparator() {
083:                    public int compare(Viewer viewer, Object e1, Object e2) {
084:                        ITargetPlugin p1 = (ITargetPlugin) e1;
085:                        ITargetPlugin p2 = (ITargetPlugin) e2;
086:                        return super .compare(viewer, p1.getId(), p2.getId());
087:                    }
088:                });
089:                fViewer.setInput(getTarget());
090:                fViewer
091:                        .addSelectionChangedListener(new ISelectionChangedListener() {
092:                            public void selectionChanged(
093:                                    SelectionChangedEvent event) {
094:                                updateButtons();
095:                            }
096:                        });
097:
098:                toolkit.paintBordersFor(container);
099:                section.setClient(container);
100:                GridData gd = new GridData(GridData.FILL_BOTH);
101:                section.setLayoutData(gd);
102:                updateButtons();
103:                getModel().addModelChangedListener(this );
104:            }
105:
106:            public boolean doGlobalAction(String actionId) {
107:                if (actionId.equals(ActionFactory.DELETE.getId())) {
108:                    handleRemove();
109:                    return true;
110:                }
111:                if (actionId.equals(ActionFactory.CUT.getId())) {
112:                    // delete here and let the editor transfer
113:                    // the selection to the clipboard
114:                    handleRemove();
115:                    return false;
116:                }
117:                if (actionId.equals(ActionFactory.PASTE.getId())) {
118:                    doPaste();
119:                    return true;
120:                }
121:                return false;
122:            }
123:
124:            private void updateButtons() {
125:                TablePart part = getTablePart();
126:                boolean empty = fViewer.getSelection().isEmpty();
127:                part.setButtonEnabled(1, !empty);
128:                boolean hasElements = fViewer.getTable().getItemCount() > 0;
129:                part.setButtonEnabled(2, hasElements);
130:            }
131:
132:            protected void buttonSelected(int index) {
133:                switch (index) {
134:                case ADD_INDEX:
135:                    handleAdd();
136:                    break;
137:                case REMOVE_INDEX:
138:                    handleRemove();
139:                    break;
140:                case REMOVE_ALL_INDEX:
141:                    handleRemoveAll();
142:                }
143:            }
144:
145:            protected void handleAdd() {
146:                ElementListSelectionDialog dialog = new ElementListSelectionDialog(
147:                        PDEPlugin.getActiveWorkbenchShell(), PDEPlugin
148:                                .getDefault().getLabelProvider());
149:
150:                dialog.setElements(getValidBundles());
151:                dialog.setTitle(PDEUIMessages.PluginSelectionDialog_title);
152:                dialog.setMessage(PDEUIMessages.PluginSelectionDialog_message);
153:                dialog.setMultipleSelection(true);
154:                if (dialog.open() == Window.OK) {
155:                    Object[] models = dialog.getResult();
156:                    ArrayList pluginsToAdd = new ArrayList();
157:                    ITargetModel model = getModel();
158:                    for (int i = 0; i < models.length; i++) {
159:                        BundleDescription desc = (BundleDescription) models[i];
160:                        ITargetPlugin plugin = model.getFactory()
161:                                .createPlugin();
162:                        plugin.setId(desc.getSymbolicName());
163:                        plugin.setModel(model);
164:                        pluginsToAdd.add(plugin);
165:                    }
166:                    getImplicitPluginsInfo().addPlugins(
167:                            (ITargetPlugin[]) pluginsToAdd
168:                                    .toArray(new ITargetPlugin[pluginsToAdd
169:                                            .size()]));
170:                    updateButtons();
171:                }
172:            }
173:
174:            protected Object[] getValidBundles() {
175:                ITargetPlugin[] plugins = getImplicitPluginsInfo().getPlugins();
176:                Set currentPlugins = new HashSet((4 / 3) * plugins.length + 1);
177:                for (int i = 0; i < plugins.length; i++) {
178:                    currentPlugins.add(plugins[i].getId());
179:                }
180:
181:                IPluginModelBase[] models = PluginRegistry
182:                        .getActiveModels(false);
183:                Set result = new HashSet((4 / 3) * models.length + 1);
184:                for (int i = 0; i < models.length; i++) {
185:                    BundleDescription desc = models[i].getBundleDescription();
186:                    if (desc != null) {
187:                        if (!currentPlugins.contains(desc.getSymbolicName()))
188:                            result.add(desc);
189:                    }
190:                }
191:                return result.toArray();
192:            }
193:
194:            protected void handleRemove() {
195:                Object[] src = ((IStructuredSelection) fViewer.getSelection())
196:                        .toArray();
197:                ITargetPlugin[] plugins = new ITargetPlugin[src.length];
198:                System.arraycopy(src, 0, plugins, 0, src.length);
199:                getImplicitPluginsInfo().removePlugins(plugins);
200:                updateButtons();
201:            }
202:
203:            protected void handleRemoveAll() {
204:                IImplicitDependenciesInfo info = getImplicitPluginsInfo();
205:                info.removePlugins(info.getPlugins());
206:                updateButtons();
207:            }
208:
209:            private IImplicitDependenciesInfo getImplicitPluginsInfo() {
210:                IImplicitDependenciesInfo info = getTarget()
211:                        .getImplicitPluginsInfo();
212:                if (info == null) {
213:                    info = getModel().getFactory().createImplicitPluginInfo();
214:                    getTarget().setImplicitPluginsInfo(info);
215:                }
216:                return info;
217:            }
218:
219:            private ITarget getTarget() {
220:                return getModel().getTarget();
221:            }
222:
223:            private ITargetModel getModel() {
224:                return (ITargetModel) getPage().getPDEEditor()
225:                        .getAggregateModel();
226:            }
227:
228:            /* (non-Javadoc)
229:             * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
230:             */
231:            public void modelChanged(IModelChangedEvent e) {
232:                if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
233:                    handleModelEventWorldChanged(e);
234:                    return;
235:                }
236:                if (e.getChangeType() == IModelChangedEvent.CHANGE
237:                        && e.getChangedProperty().equals(
238:                                IImplicitDependenciesInfo.P_IMPLICIT_PLUGINS)) {
239:                    ITargetPlugin[] plugins = (ITargetPlugin[]) e.getOldValue();
240:                    for (int i = 0; i < plugins.length; i++)
241:                        fViewer.remove(plugins[i]);
242:                    plugins = (ITargetPlugin[]) e.getNewValue();
243:                    for (int i = 0; i < plugins.length; i++)
244:                        fViewer.add(plugins[i]);
245:                }
246:            }
247:
248:            /**
249:             * @param event
250:             */
251:            private void handleModelEventWorldChanged(IModelChangedEvent event) {
252:                // Reload input
253:                fViewer.setInput(getTarget());
254:                // Perform the refresh
255:                refresh();
256:            }
257:
258:            /* (non-Javadoc)
259:             * @see org.eclipse.ui.forms.AbstractFormPart#refresh()
260:             */
261:            public void refresh() {
262:                fViewer.refresh();
263:                updateButtons();
264:                super .refresh();
265:            }
266:
267:            /* (non-Javadoc)
268:             * @see org.eclipse.pde.internal.ui.editor.TableSection#handleDoubleClick(org.eclipse.jface.viewers.IStructuredSelection)
269:             */
270:            protected void handleDoubleClick(IStructuredSelection selection) {
271:                handleOpen(selection);
272:            }
273:
274:            private void handleOpen(IStructuredSelection selection) {
275:                Object object = selection.getFirstElement();
276:                ManifestEditor.openPluginEditor(((ITargetPlugin) object)
277:                        .getId());
278:            }
279:
280:            protected boolean canPaste(Object target, Object[] objects) {
281:                for (int i = 0; i < objects.length; i++) {
282:                    if (!(objects[i] instanceof  ITargetPlugin))
283:                        return false;
284:                }
285:                return true;
286:            }
287:
288:            protected void doPaste(Object target, Object[] objects) {
289:                for (int i = 0; i < objects.length; i++) {
290:                    if (objects[i] instanceof  ITargetPlugin)
291:                        getImplicitPluginsInfo().addPlugin(
292:                                (ITargetPlugin) objects[i]);
293:                }
294:            }
295:
296:            protected void selectionChanged(IStructuredSelection selection) {
297:                getPage().getPDEEditor().setSelection(selection);
298:            }
299:
300:            public void dispose() {
301:                ITargetModel model = getModel();
302:                if (model != null)
303:                    model.removeModelChangedListener(this );
304:            }
305:
306:            protected boolean createCount() {
307:                return true;
308:            }
309:        }
w___ww.__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.