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


001:        package net.refractions.udig.catalog.ui;
002:
003:        import java.util.ArrayList;
004:        import java.util.List;
005:
006:        import net.refractions.udig.catalog.ui.internal.Messages;
007:        import net.refractions.udig.catalog.ui.workflow.DataSourceSelectionState;
008:        import net.refractions.udig.catalog.ui.workflow.WorkflowWizardPage;
009:        import net.refractions.udig.internal.ui.UiPlugin;
010:
011:        import org.eclipse.jface.dialogs.Dialog;
012:        import org.eclipse.jface.dialogs.IDialogConstants;
013:        import org.eclipse.jface.resource.ImageDescriptor;
014:        import org.eclipse.jface.resource.ImageRegistry;
015:        import org.eclipse.jface.viewers.ArrayContentProvider;
016:        import org.eclipse.jface.viewers.DoubleClickEvent;
017:        import org.eclipse.jface.viewers.IDoubleClickListener;
018:        import org.eclipse.jface.viewers.ISelectionChangedListener;
019:        import org.eclipse.jface.viewers.IStructuredSelection;
020:        import org.eclipse.jface.viewers.LabelProvider;
021:        import org.eclipse.jface.viewers.SelectionChangedEvent;
022:        import org.eclipse.jface.viewers.StructuredSelection;
023:        import org.eclipse.jface.viewers.TableViewer;
024:        import org.eclipse.jface.viewers.Viewer;
025:        import org.eclipse.jface.wizard.IWizardContainer;
026:        import org.eclipse.swt.SWT;
027:        import org.eclipse.swt.graphics.Image;
028:        import org.eclipse.swt.layout.FillLayout;
029:        import org.eclipse.swt.widgets.Button;
030:        import org.eclipse.swt.widgets.Composite;
031:        import org.eclipse.swt.widgets.Control;
032:        import org.eclipse.swt.widgets.Event;
033:
034:        /**
035:         * This is a wizard page which is used to select from a set of data sources.
036:         * <p>
037:         * Each data source is described an instance of
038:         * 
039:         * @see net.refractions.udig.catalog.ui.UDIGImportPageDescriptor.
040:         *      </p>
041:         *      <p>
042:         *      Client code may instantiate objects of this class,but may only call
043:         *      setSelectedDescriptor(UDIGImportPageDescriptor). All other methods are
044:         *      wizard lifecycle methods.page
045:         *      </p>
046:         * @author Justin Deoliveira,Refractions Research Inc.,jdeolive@refractions.net
047:         */
048:        public class DataSourceSelectionPage extends WorkflowWizardPage
049:                implements  ISelectionChangedListener {
050:
051:            /** the selected extension * */
052:            private IStructuredSelection selected;
053:
054:            /** list of wizard page extension* */
055:            private List<UDIGConnectionFactoryDescriptor> descriptors;
056:
057:            /** the viewer to select * */
058:            private WizardViewer viewer;
059:
060:            public DataSourceSelectionPage() {
061:                super ("dataSourceWizardPage"); //$NON-NLS-1$
062:                setTitle(Messages.DataSourceSelectionPage_pageTitle);
063:                setDescription(Messages.DataSourceSelectionPage_defaultMessage);
064:            }
065:
066:            /**
067:             * Sets the selected set of import page descriptiors.
068:             * 
069:             * @param ids
070:             *            A list of import page identifiers.
071:             * 
072:             */
073:            public void select(List<String> ids) {
074:                descriptors = ConnectionFactoryManager.instance()
075:                        .getConnectionFactoryDescriptors(ids);
076:                setSelection(descriptors);
077:            }
078:
079:            /**
080:             * Sets the selected import page descriptor.
081:             * 
082:             * @param id
083:             *            The id of the import page to select.
084:             */
085:            public void select(String id) {
086:                ArrayList<String> l = new ArrayList<String>();
087:                l.add(id);
088:                select(l);
089:            }
090:
091:            /**
092:             * Sets the selected import page descriptor.
093:             * 
094:             * @param descriptor
095:             *            The descriptor to be selected.
096:             */
097:            public void setSelection(
098:                    List<UDIGConnectionFactoryDescriptor> descriptors) {
099:                selected = new StructuredSelection(descriptors);
100:                if (viewer != null) {
101:                    // only set first in viewer
102:                    if (!selected.isEmpty()) {
103:                        viewer.setSelection(new StructuredSelection(selected
104:                                .getFirstElement()));
105:                    } else {
106:                        viewer.setSelection(new StructuredSelection());
107:                    }
108:                }
109:            }
110:
111:            @Override
112:            public boolean canFlipToNextPage() {
113:                boolean more = super .canFlipToNextPage();
114:                if (more) {
115:                    // if selection set, we are done
116:                    if (selected != null && selected.size() == 1) {
117:                        return true;
118:                    }
119:
120:                    // if there is only one choice, we are also done
121:                    if (descriptors != null && descriptors.size() == 1)
122:
123:                        return true;
124:
125:                    return false;
126:                }
127:
128:                return false;
129:            }
130:
131:            /**
132:             * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
133:             */
134:            public void createControl(Composite parent) {
135:
136:                Composite comp = new Composite(parent, SWT.NONE);
137:                comp.setLayout(new FillLayout());
138:
139:                viewer = new WizardViewer(comp, SWT.SINGLE | SWT.BORDER);
140:                viewer.setInput(getDescriptors().toArray());
141:                viewer.addDoubleClickListener(new IDoubleClickListener() {
142:                    public void doubleClick(DoubleClickEvent event) {
143:                        IWizardContainer container = getContainer();
144:                        if (container instanceof  Dialog) {
145:                            Dialog d = (Dialog) container;
146:                            Button button = findButton(d.buttonBar,
147:                                    IDialogConstants.NEXT_ID);
148:                            if (button != null)
149:                                button.notifyListeners(SWT.Selection,
150:                                        new Event());
151:                        }
152:                    }
153:                });
154:                viewer.addSelectionChangedListener(this );
155:
156:                // check the state for an initial selection
157:                DataSourceSelectionState state = (DataSourceSelectionState) getState();
158:                if (state.getDescriptor() != null)
159:                    viewer.setSelection(new StructuredSelection(state
160:                            .getDescriptor()));
161:
162:                setControl(comp);
163:            }
164:
165:            protected Button findButton(Control buttonBar, int buttonID) {
166:                if (buttonBar instanceof  Composite) {
167:                    Composite composite = (Composite) buttonBar;
168:                    Control[] children = composite.getChildren();
169:                    for (Control control : children) {
170:                        if (control instanceof  Button) {
171:                            Button button = (Button) control;
172:                            if (((Integer) button.getData()).intValue() == buttonID)
173:                                return button;
174:                        } else if (control instanceof  Composite) {
175:                            Button button = findButton(control, buttonID);
176:                            if (button != null)
177:                                return button;
178:                        }
179:                    }
180:                }
181:                if (buttonBar instanceof  Button) {
182:                    Button button = (Button) buttonBar;
183:                    if (((Integer) button.getData()).intValue() == buttonID)
184:                        return button;
185:                }
186:
187:                return null;
188:            }
189:
190:            /**
191:             * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
192:             */
193:            public void selectionChanged(SelectionChangedEvent event) {
194:                selected = (IStructuredSelection) event.getSelection();
195:                if (selected != null && !selected.isEmpty()) {
196:                    UDIGConnectionFactoryDescriptor descriptor = (UDIGConnectionFactoryDescriptor) selected
197:                            .getFirstElement();
198:
199:                    // change the page description + image
200:                    setImageDescriptor(descriptor.getDescriptionImage());
201:                    setMessage(descriptor.getDescription());
202:
203:                    // update the underlying state
204:                    DataSourceSelectionState state = (DataSourceSelectionState) getState();
205:                    state.setDescriptor(descriptor);
206:                }
207:
208:                // update the container buttons
209:                getWizard().getContainer().updateButtons();
210:            }
211:
212:            public Viewer getViewer() {
213:                return viewer;
214:            }
215:
216:            public List<UDIGConnectionFactoryDescriptor> getDescriptors() {
217:
218:                List<UDIGConnectionFactoryDescriptor> connectionFactoryDescriptors = ConnectionFactoryManager
219:                        .instance().getConnectionFactoryDescriptors();
220:                return connectionFactoryDescriptors;
221:            }
222:
223:            protected void saveSelectedDescriptor() {
224:                IStructuredSelection selection = (IStructuredSelection) viewer
225:                        .getSelection();
226:                if (selection.isEmpty())
227:                    return;
228:            }
229:
230:            private static class WizardViewer extends TableViewer {
231:
232:                public WizardViewer(Composite parent, int style) {
233:                    super (parent, style);
234:
235:                    setContentProvider(new ArrayContentProvider());
236:                    setLabelProvider(new LabelProvider() {
237:                        public String getText(Object object) {
238:                            UDIGConnectionFactoryDescriptor descriptor = (UDIGConnectionFactoryDescriptor) object;
239:
240:                            return descriptor.getLabel();
241:                        }
242:
243:                        public Image getImage(Object object) {
244:                            UDIGConnectionFactoryDescriptor descriptor = (UDIGConnectionFactoryDescriptor) object;
245:
246:                            String id = descriptor.getId();
247:                            ImageRegistry registry = UiPlugin.getDefault()
248:                                    .getImageRegistry();
249:                            ImageDescriptor image = descriptor.getImage();
250:                            synchronized (registry) {
251:                                if (registry.get(id) == null && image != null) {
252:                                    registry.put(id, image);
253:                                }
254:
255:                                return registry.get(id);
256:                            }
257:                        }
258:                    });
259:                }
260:            }
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.