Source Code Cross Referenced for FeatureEditorLoader.java in  » GIS » udig-1.1 » net » refractions » udig » project » ui » internal » 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 » GIS » udig 1.1 » net.refractions.udig.project.ui.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation;
008:         * version 2.1 of the License.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         */
015:        package net.refractions.udig.project.ui.internal;
016:
017:        import net.refractions.udig.internal.ui.UiPlugin;
018:        import net.refractions.udig.project.ui.IUDIGDialogPage;
019:        import net.refractions.udig.project.ui.IUDIGView;
020:        import net.refractions.udig.project.ui.internal.FeatureEditorExtensionProcessor.EditActionContribution;
021:        import net.refractions.udig.project.ui.internal.tool.ToolContext;
022:
023:        import org.eclipse.core.runtime.CoreException;
024:        import org.eclipse.core.runtime.IConfigurationElement;
025:        import org.eclipse.jface.action.Action;
026:        import org.eclipse.jface.action.IAction;
027:        import org.eclipse.jface.dialogs.Dialog;
028:        import org.eclipse.jface.resource.ImageDescriptor;
029:        import org.eclipse.jface.viewers.ISelection;
030:        import org.eclipse.jface.viewers.IStructuredSelection;
031:        import org.eclipse.swt.SWT;
032:        import org.eclipse.swt.widgets.Display;
033:        import org.eclipse.swt.widgets.Shell;
034:        import org.eclipse.ui.IWorkbenchPage;
035:        import org.eclipse.ui.PartInitException;
036:        import org.eclipse.ui.PlatformUI;
037:        import org.eclipse.ui.plugin.AbstractUIPlugin;
038:        import org.geotools.feature.Feature;
039:
040:        public class FeatureEditorLoader {
041:            /** FeatureEditorLoader processor field */
042:            final FeatureEditorExtensionProcessor processor;
043:
044:            private String dialogPage;
045:
046:            String viewId;
047:
048:            private String name;
049:
050:            String id;
051:
052:            ImageDescriptor icon;
053:
054:            IAction contribution;
055:
056:            private IConfigurationElement definition;
057:
058:            private FeatureTypeMatch featureTypeMatcher;
059:
060:            FeatureEditorLoader(FeatureEditorExtensionProcessor processor,
061:                    IConfigurationElement definition) {
062:                this .processor = processor;
063:                String iconID = definition.getAttribute("icon"); //$NON-NLS-1$
064:                if (iconID != null) {
065:                    icon = AbstractUIPlugin.imageDescriptorFromPlugin(
066:                            definition.getNamespaceIdentifier(), iconID);
067:                }
068:
069:                id = definition.getAttribute("id"); //$NON-NLS-1$
070:                name = definition.getAttribute("name"); //$NON-NLS-1$
071:                viewId = definition.getAttribute("viewId"); //$NON-NLS-1$
072:                dialogPage = definition.getAttribute("dialogPage"); //$NON-NLS-1$
073:                this .definition = definition;
074:                IConfigurationElement[] featureTypeDef = definition
075:                        .getChildren("featureType");//$NON-NLS-1$
076:                if (featureTypeDef.length == 1)
077:                    this .featureTypeMatcher = new FeatureTypeMatch(
078:                            featureTypeDef[0]);
079:                else
080:                    this .featureTypeMatcher = FeatureTypeMatch.ALL;
081:            }
082:
083:            IAction getAction(final ISelection selection) {
084:                if (!(selection instanceof  IStructuredSelection))
085:                    return null;
086:
087:                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
088:                if (!processor.sameFeatureTypes(structuredSelection))
089:                    return null;
090:
091:                final Feature feature = (Feature) structuredSelection
092:                        .getFirstElement();
093:                if (featureTypeMatcher.matches(feature) == -1)
094:                    return null;
095:                contribution = new Action(name, IAction.AS_RADIO_BUTTON) {
096:                    public void runWithEvent(org.eclipse.swt.widgets.Event event) {
097:
098:                        // note: when the gui is used the contribution is checked by the framework.
099:                        // so the gui must be used in order to test this.
100:                        if (contribution.isChecked()) {
101:                            processor.createEditAction(
102:                                    FeatureEditorLoader.this , selection,
103:                                    feature);
104:                            open(event.display, selection);
105:                        }
106:                    }
107:                };
108:                contribution.setId(id);
109:                contribution.setImageDescriptor(icon);
110:                EditActionContribution selected = this .processor.selectedEditors
111:                        .get(feature.getFeatureType());
112:                if (selected == null) {
113:                    selected = processor.createEditAction(processor
114:                            .getClosestMatch(selection), selection, feature);
115:                } else {
116:                    selected.setSelection(selection);
117:                }
118:                if (selected != null && selected.getId().equals(id))
119:                    contribution.setChecked(true);
120:                else
121:                    contribution.setChecked(false);
122:
123:                return contribution;
124:            }
125:
126:            public void open(Display display, ISelection selection) {
127:                Feature feature = (Feature) ((IStructuredSelection) selection)
128:                        .getFirstElement();
129:
130:                if (viewId != null) {
131:                    try {
132:                        IUDIGView view = (IUDIGView) PlatformUI.getWorkbench()
133:                                .getActiveWorkbenchWindow().getActivePage()
134:                                .showView(viewId, null,
135:                                        IWorkbenchPage.VIEW_VISIBLE);
136:                        try {
137:                            view.editFeatureChanged(feature);
138:                        } catch (Throwable e) {
139:                            UiPlugin.log(view + " threw an exception", e); //$NON-NLS-1$
140:                        }
141:                    } catch (PartInitException e) {
142:                        ProjectUIPlugin.log(null, e);
143:                    }
144:                } else if (dialogPage != null) {
145:                    try {
146:                        IUDIGDialogPage page = (IUDIGDialogPage) definition
147:                                .createExecutableExtension("dialogPage"); //$NON-NLS-1$
148:                        ToolContext toolContext;
149:                        synchronized (this .processor.partListener) {
150:                            toolContext = this .processor.partListener.currentContext;
151:                        }
152:                        page.setContext(toolContext);
153:                        Dialog dialog = new FeatureEditorExtensionProcessor.EditorDialog(
154:                                new Shell(display.getActiveShell(), SWT.RESIZE
155:                                        | SWT.PRIMARY_MODAL), page);
156:                        dialog.setBlockOnOpen(false);
157:                        page.setFeature(feature);
158:                        dialog.open();
159:
160:                        PlatformUI
161:                                .getPreferenceStore()
162:                                .putValue(
163:                                        FeatureEditorExtensionProcessor.CURRENT_LOADER_ID,
164:                                        id);
165:
166:                    } catch (CoreException e) {
167:                        ProjectUIPlugin.log(null, e);
168:                    }
169:
170:                }
171:            }
172:
173:            /**
174:             * Returns an integer indicating the accuracy of the match between a featureType and the one
175:             * declared in the FeatureEditor extension declaration.
176:             * <p>
177:             * -1 indicates no match, 0 a perfect match and each number higher is a match but a poorer
178:             * match.
179:             * </p>
180:             * 
181:             * @param selection
182:             * @return
183:             */
184:            public int match(ISelection selection) {
185:                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
186:                if (!processor.sameFeatureTypes(structuredSelection))
187:                    return -1;
188:
189:                final Feature feature = (Feature) structuredSelection
190:                        .getFirstElement();
191:                return featureTypeMatcher.matches(feature);
192:            }
193:
194:            /**
195:             * Returns the dialog page if the feature editor is a dialog, or null otherwise.
196:             * 
197:             * @return the dialog page if the feature editor is a dialog, or null otherwise.
198:             */
199:            public String getDialogPage() {
200:                return dialogPage;
201:            }
202:
203:            /**
204:             * Returns the name of the feature editor
205:             * 
206:             * @returnthe name of the feature editor
207:             */
208:            public String getName() {
209:                return name;
210:            }
211:
212:            /**
213:             * Returns the viewid if the feature editor is a view, or null otherwise.
214:             * 
215:             * @return the dviewid if the feature editor is a view, or null otherwise.
216:             */
217:            public String getViewId() {
218:                return viewId;
219:            }
220:
221:            public String getId() {
222:                return id;
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.