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


001:        /*******************************************************************************
002:         * Copyright (c) 2006 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.commands;
011:
012:        import java.util.ArrayList;
013:
014:        import org.eclipse.core.commands.Command;
015:        import org.eclipse.core.commands.IParameter;
016:        import org.eclipse.core.commands.ParameterType;
017:        import org.eclipse.core.commands.common.CommandException;
018:        import org.eclipse.jface.viewers.ISelection;
019:        import org.eclipse.jface.viewers.IStructuredSelection;
020:        import org.eclipse.swt.SWT;
021:        import org.eclipse.swt.events.DisposeEvent;
022:        import org.eclipse.swt.events.DisposeListener;
023:        import org.eclipse.swt.layout.GridData;
024:        import org.eclipse.swt.layout.GridLayout;
025:        import org.eclipse.swt.widgets.Composite;
026:        import org.eclipse.swt.widgets.Group;
027:        import org.eclipse.swt.widgets.Label;
028:        import org.eclipse.ui.ISelectionListener;
029:        import org.eclipse.ui.ISelectionService;
030:        import org.eclipse.ui.IWorkbenchPart;
031:        import org.eclipse.ui.IWorkbenchWindow;
032:        import org.eclipse.ui.PlatformUI;
033:
034:        public class QueryByObjectSelection extends QueryControl {
035:
036:            private Label fObjectSelectionLabel;
037:            private Label fLabel;
038:            private SelectionTracker fSelectionTracker;
039:            private Object fObjectSelection;
040:
041:            public QueryByObjectSelection(CommandComposerPart csp,
042:                    Composite comp) {
043:                super (csp, comp);
044:            }
045:
046:            protected void createGroupContents(Group parent) {
047:                Composite comp = fToolkit.createComposite(parent);
048:                GridLayout layout = new GridLayout(2, false);
049:                layout.marginHeight = layout.marginWidth = 0;
050:                comp.setLayout(layout);
051:                comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
052:                fLabel = fToolkit.createLabel(comp, "selection: "); //$NON-NLS-1$
053:                fObjectSelectionLabel = fToolkit.createLabel(comp,
054:                        "<no selection>", SWT.BORDER); //$NON-NLS-1$
055:                fObjectSelectionLabel.setLayoutData(new GridData(
056:                        GridData.FILL_HORIZONTAL));
057:
058:                IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
059:                        .getActiveWorkbenchWindow();
060:                if (activeWindow != null) {
061:                    ISelectionService selectionService = activeWindow
062:                            .getSelectionService();
063:                    if (selectionService != null) {
064:                        fSelectionTracker = new SelectionTracker(
065:                                selectionService);
066:                    }
067:                }
068:
069:                parent.addDisposeListener(new DisposeListener() {
070:                    public void widgetDisposed(DisposeEvent e) {
071:                        if (fSelectionTracker != null) {
072:                            fSelectionTracker.dispose();
073:                        }
074:                    }
075:                });
076:            }
077:
078:            protected String getName() {
079:                return "Query Commands by selected object"; //$NON-NLS-1$
080:            }
081:
082:            private class SelectionTracker implements  ISelectionListener {
083:
084:                private final ISelectionService _selectionService;
085:
086:                public SelectionTracker(ISelectionService selectionService) {
087:                    _selectionService = selectionService;
088:                    _selectionService.addSelectionListener(this );
089:                }
090:
091:                public void selectionChanged(IWorkbenchPart part,
092:                        ISelection selection) {
093:                    if (selection instanceof  IStructuredSelection) {
094:                        Object selected = ((IStructuredSelection) selection)
095:                                .getFirstElement();
096:
097:                        if (selected != null) {
098:                            fObjectSelection = selected;
099:                            String typeName = selected.getClass().getName();
100:                            fObjectSelectionLabel.setToolTipText(typeName);
101:
102:                            int dotPosition = typeName.lastIndexOf('.');
103:                            if (dotPosition != -1) {
104:                                typeName = typeName.substring(dotPosition + 1);
105:                            }
106:                            fObjectSelectionLabel.setText(typeName);
107:                        }
108:                    }
109:                }
110:
111:                public void dispose() {
112:                    _selectionService.removeSelectionListener(this );
113:                }
114:            }
115:
116:            private boolean hasTypedParameterMatch(Command command,
117:                    Object object) throws CommandException {
118:                IParameter[] params = command.getParameters();
119:                if (params != null) {
120:                    for (int i = 0; i < params.length; i++) {
121:                        IParameter param = params[i];
122:                        ParameterType parameterType = command
123:                                .getParameterType(param.getId());
124:                        if (parameterType != null) {
125:                            if (parameterType.isCompatible(object))
126:                                return true;
127:                        }
128:                    }
129:                }
130:
131:                return false;
132:            }
133:
134:            protected Command[] getCommands() {
135:                Object objectSelection = fObjectSelection;
136:                if (objectSelection == null)
137:                    return null;
138:
139:                ArrayList hitList = new ArrayList();
140:                Command[] commands = getCommandService().getDefinedCommands();
141:                for (int i = 0; i < commands.length; i++) {
142:                    Command command = commands[i];
143:                    try {
144:                        if (hasTypedParameterMatch(command, objectSelection))
145:                            hitList.add(command);
146:                    } catch (CommandException ex) {
147:                    }
148:                }
149:
150:                return (Command[]) hitList.toArray(new Command[hitList.size()]);
151:            }
152:
153:            protected void enable(boolean enable) {
154:                fGroup.setEnabled(enable);
155:                fLabel.setEnabled(enable);
156:                fObjectSelectionLabel.setEnabled(enable);
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.