Source Code Cross Referenced for WizardExportPage.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » dialogs » 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 » ui ide » org.eclipse.ui.dialogs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.ui.dialogs;
011:
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.Iterator;
015:        import java.util.List;
016:        import java.util.StringTokenizer;
017:        import java.util.Vector;
018:
019:        import org.eclipse.core.resources.IContainer;
020:        import org.eclipse.core.resources.IFile;
021:        import org.eclipse.core.resources.IProject;
022:        import org.eclipse.core.resources.IResource;
023:        import org.eclipse.core.resources.IWorkspace;
024:        import org.eclipse.core.resources.IWorkspaceRoot;
025:        import org.eclipse.core.resources.ResourcesPlugin;
026:        import org.eclipse.core.runtime.CoreException;
027:        import org.eclipse.core.runtime.IAdaptable;
028:        import org.eclipse.core.runtime.IPath;
029:        import org.eclipse.core.runtime.IStatus;
030:        import org.eclipse.jface.dialogs.IDialogSettings;
031:        import org.eclipse.jface.dialogs.MessageDialog;
032:        import org.eclipse.jface.viewers.IStructuredSelection;
033:        import org.eclipse.jface.viewers.StructuredSelection;
034:        import org.eclipse.osgi.util.NLS;
035:        import org.eclipse.swt.SWT;
036:        import org.eclipse.swt.layout.GridData;
037:        import org.eclipse.swt.layout.GridLayout;
038:        import org.eclipse.swt.widgets.Button;
039:        import org.eclipse.swt.widgets.Combo;
040:        import org.eclipse.swt.widgets.Composite;
041:        import org.eclipse.swt.widgets.Event;
042:        import org.eclipse.swt.widgets.Label;
043:        import org.eclipse.swt.widgets.Text;
044:        import org.eclipse.swt.widgets.Widget;
045:        import org.eclipse.ui.IFileEditorMapping;
046:        import org.eclipse.ui.PlatformUI;
047:        import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
048:        import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
049:
050:        /**
051:         * Abstract superclass for a typical export wizard's main page.
052:         * <p>
053:         * Clients may subclass this page to inherit its common destination resource
054:         * selection facilities.
055:         * </p>
056:         * <p>
057:         * Subclasses must implement 
058:         * <ul>
059:         *   <li><code>createDestinationGroup</code></li>
060:         * </ul>
061:         * </p>
062:         * <p>
063:         * Subclasses may override
064:         * <ul>
065:         *   <li><code>allowNewContainerName</code></li>
066:         * </ul>
067:         * </p>
068:         * <p>
069:         * Subclasses may extend
070:         * <ul>
071:         *   <li><code>handleEvent</code></li>
072:         *   <li><code>internalSaveWidgetValues</code></li>
073:         *   <li><code>updateWidgetEnablements</code></li>
074:         * </ul>
075:         * </p>
076:         * @deprecated use WizardExportResourcePage
077:         */
078:        public abstract class WizardExportPage extends WizardDataTransferPage {
079:            private IStructuredSelection currentResourceSelection;
080:
081:            private List selectedResources;
082:
083:            private List selectedTypes;
084:
085:            private boolean exportCurrentSelection = false;
086:
087:            private boolean exportAllResourcesPreSet = false;
088:
089:            // widgets
090:            private Combo typesToExportField;
091:
092:            private Button typesToExportEditButton;
093:
094:            private Button exportAllTypesRadio;
095:
096:            private Button exportSpecifiedTypesRadio;
097:
098:            private Button resourceDetailsButton;
099:
100:            private Label resourceDetailsDescription;
101:
102:            private Text resourceNameField;
103:
104:            private Button resourceBrowseButton;
105:
106:            // initial value stores
107:            private boolean initialExportAllTypesValue = true;
108:
109:            private String initialExportFieldValue;
110:
111:            private String initialTypesFieldValue;
112:
113:            // constants
114:            private static final String CURRENT_SELECTION = "<current selection>";//$NON-NLS-1$
115:
116:            private static final String TYPE_DELIMITER = ",";//$NON-NLS-1$
117:
118:            // dialog store id constants
119:            private static final String STORE_SELECTED_TYPES_ID = "WizardFileSystemExportPage1.STORE_SELECTED_TYPES_ID.";//$NON-NLS-1$
120:
121:            private static final String STORE_EXPORT_ALL_RESOURCES_ID = "WizardFileSystemExportPage1.STORE_EXPORT_ALL_RESOURCES_ID.";//$NON-NLS-1$
122:
123:            /**
124:             * Creates an export wizard page. If the current resource selection 
125:             * is not empty then it will be used as the initial collection of resources
126:             * selected for export.
127:             *
128:             * @param pageName the name of the page
129:             * @param selection the current resource selection
130:             */
131:            protected WizardExportPage(String pageName,
132:                    IStructuredSelection selection) {
133:                super (pageName);
134:                this .currentResourceSelection = selection;
135:            }
136:
137:            /**
138:             * The <code>WizardExportPage</code> implementation of this 
139:             * <code>WizardDataTransferPage</code> method returns <code>false</code>. 
140:             * Subclasses may override this method.
141:             */
142:            protected boolean allowNewContainerName() {
143:                return false;
144:            }
145:
146:            /** (non-Javadoc)
147:             * Method declared on IDialogPage.
148:             */
149:            public void createControl(Composite parent) {
150:                Composite composite = new Composite(parent, SWT.NULL);
151:                composite.setLayout(new GridLayout());
152:                composite.setLayoutData(new GridData(
153:                        GridData.VERTICAL_ALIGN_FILL
154:                                | GridData.HORIZONTAL_ALIGN_FILL));
155:
156:                createBoldLabel(composite,
157:                        IDEWorkbenchMessages.WizardExportPage_whatLabel);
158:                createSourceGroup(composite);
159:
160:                createSpacer(composite);
161:
162:                createBoldLabel(composite,
163:                        IDEWorkbenchMessages.WizardExportPage_whereLabel);
164:                createDestinationGroup(composite);
165:
166:                createSpacer(composite);
167:
168:                createBoldLabel(composite,
169:                        IDEWorkbenchMessages.WizardExportPage_options);
170:                createOptionsGroup(composite);
171:
172:                restoreResourceSpecificationWidgetValues(); // ie.- local
173:                restoreWidgetValues(); // ie.- subclass hook
174:                if (currentResourceSelection != null) {
175:                    setupBasedOnInitialSelections();
176:                }
177:
178:                updateWidgetEnablements();
179:                setPageComplete(determinePageCompletion());
180:
181:                setControl(composite);
182:            }
183:
184:            /**
185:             * Creates the export destination specification visual components.
186:             * <p>
187:             * Subclasses must implement this method.
188:             * </p>
189:             *
190:             * @param parent the parent control
191:             */
192:            protected abstract void createDestinationGroup(Composite parent);
193:
194:            /**
195:             * Creates the export source resource specification controls.
196:             *
197:             * @param parent the parent control
198:             */
199:            protected final void createSourceGroup(Composite parent) {
200:                // top level group
201:                Composite sourceGroup = new Composite(parent, SWT.NONE);
202:                GridLayout layout = new GridLayout();
203:                layout.numColumns = 3;
204:                sourceGroup.setLayout(layout);
205:                sourceGroup.setLayoutData(new GridData(
206:                        GridData.VERTICAL_ALIGN_FILL
207:                                | GridData.HORIZONTAL_ALIGN_FILL));
208:
209:                // resource label
210:                new Label(sourceGroup, SWT.NONE)
211:                        .setText(IDEWorkbenchMessages.WizardExportPage_folder);
212:
213:                // resource name entry field
214:                resourceNameField = new Text(sourceGroup, SWT.SINGLE
215:                        | SWT.BORDER);
216:                resourceNameField.addListener(SWT.KeyDown, this );
217:                GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
218:                        | GridData.GRAB_HORIZONTAL);
219:                data.widthHint = SIZING_TEXT_FIELD_WIDTH;
220:                resourceNameField.setLayoutData(data);
221:
222:                // resource browse button
223:                resourceBrowseButton = new Button(sourceGroup, SWT.PUSH);
224:                resourceBrowseButton
225:                        .setText(IDEWorkbenchMessages.WizardExportPage_browse);
226:                resourceBrowseButton.addListener(SWT.Selection, this );
227:                resourceBrowseButton.setLayoutData(new GridData(
228:                        GridData.HORIZONTAL_ALIGN_FILL
229:                                | GridData.GRAB_HORIZONTAL));
230:
231:                // export all types radio	
232:                exportAllTypesRadio = new Button(sourceGroup, SWT.RADIO);
233:                exportAllTypesRadio
234:                        .setText(IDEWorkbenchMessages.WizardExportPage_allTypes);
235:                exportAllTypesRadio.addListener(SWT.Selection, this );
236:                data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
237:                        | GridData.GRAB_HORIZONTAL);
238:                data.horizontalSpan = 3;
239:                exportAllTypesRadio.setLayoutData(data);
240:
241:                // export specific types radio
242:                exportSpecifiedTypesRadio = new Button(sourceGroup, SWT.RADIO);
243:                exportSpecifiedTypesRadio
244:                        .setText(IDEWorkbenchMessages.WizardExportPage_specificTypes);
245:                exportSpecifiedTypesRadio.addListener(SWT.Selection, this );
246:
247:                // types combo
248:                typesToExportField = new Combo(sourceGroup, SWT.NONE);
249:                data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
250:                        | GridData.GRAB_HORIZONTAL);
251:                data.widthHint = SIZING_TEXT_FIELD_WIDTH;
252:                typesToExportField.setLayoutData(data);
253:                typesToExportField.addListener(SWT.Modify, this );
254:
255:                // types edit button
256:                typesToExportEditButton = new Button(sourceGroup, SWT.PUSH);
257:                typesToExportEditButton
258:                        .setText(IDEWorkbenchMessages.WizardExportPage_edit);
259:                typesToExportEditButton.setLayoutData(new GridData(
260:                        GridData.HORIZONTAL_ALIGN_FILL
261:                                | GridData.GRAB_HORIZONTAL
262:                                | GridData.VERTICAL_ALIGN_END));
263:                typesToExportEditButton.addListener(SWT.Selection, this );
264:
265:                // details button
266:                resourceDetailsButton = new Button(sourceGroup, SWT.PUSH);
267:                resourceDetailsButton
268:                        .setText(IDEWorkbenchMessages.WizardExportPage_details);
269:                resourceDetailsButton.addListener(SWT.Selection, this );
270:
271:                // details label
272:                resourceDetailsDescription = new Label(sourceGroup, SWT.NONE);
273:                data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
274:                        | GridData.GRAB_HORIZONTAL);
275:                data.horizontalSpan = 2;
276:                resourceDetailsDescription.setLayoutData(data);
277:
278:                // initial setup
279:                resetSelectedResources();
280:                exportAllTypesRadio.setSelection(initialExportAllTypesValue);
281:                exportSpecifiedTypesRadio
282:                        .setSelection(!initialExportAllTypesValue);
283:                typesToExportField.setEnabled(!initialExportAllTypesValue);
284:                typesToExportEditButton.setEnabled(!initialExportAllTypesValue);
285:
286:                if (initialExportFieldValue != null) {
287:                    resourceNameField.setText(initialExportFieldValue);
288:                }
289:                if (initialTypesFieldValue != null) {
290:                    typesToExportField.setText(initialTypesFieldValue);
291:                }
292:            }
293:
294:            /**
295:             * Display an error dialog with the specified message.
296:             *
297:             * @param message the error message
298:             */
299:            protected void displayErrorDialog(String message) {
300:                MessageDialog.openError(getContainer().getShell(),
301:                        IDEWorkbenchMessages.WizardExportPage_errorDialogTitle,
302:                        message);
303:            }
304:
305:            /**
306:             * Displays a description message that indicates a selection of resources
307:             * of the specified size.
308:             *
309:             * @param selectedResourceCount the resource selection size to display
310:             */
311:            protected void displayResourcesSelectedCount(
312:                    int selectedResourceCount) {
313:                if (selectedResourceCount == 1) {
314:                    resourceDetailsDescription
315:                            .setText(IDEWorkbenchMessages.WizardExportPage_oneResourceSelected);
316:                } else {
317:                    resourceDetailsDescription
318:                            .setText(NLS
319:                                    .bind(
320:                                            IDEWorkbenchMessages.WizardExportPage_resourceCountMessage,
321:                                            new Integer(selectedResourceCount)));
322:                }
323:            }
324:
325:            /**
326:             * Obsolete method. This was implemented to handle the case where ensureLocal()
327:             * needed to be called but it doesn't use it any longer.
328:             *
329:             * @param resources the list of resources to ensure locality for
330:             * @return <code>true</code> for successful completion
331:             * @deprecated Only retained for backwards compatibility.
332:             */
333:            protected boolean ensureResourcesLocal(List resources) {
334:                return true;
335:            }
336:
337:            /**
338:             * Returns a new subcollection containing only those resources which are not 
339:             * local.
340:             *
341:             * @param originalList the original list of resources (element type: 
342:             *   <code>IResource</code>)
343:             * @return the new list of non-local resources (element type: 
344:             *   <code>IResource</code>)
345:             */
346:            protected List extractNonLocalResources(List originalList) {
347:                Vector result = new Vector(originalList.size());
348:                Iterator resourcesEnum = originalList.iterator();
349:
350:                while (resourcesEnum.hasNext()) {
351:                    IResource currentResource = (IResource) resourcesEnum
352:                            .next();
353:                    if (!currentResource.isLocal(IResource.DEPTH_ZERO)) {
354:                        result.addElement(currentResource);
355:                    }
356:                }
357:
358:                return result;
359:            }
360:
361:            /**
362:             * Returns the current selection value of the "Export all types" radio,
363:             * or its set initial value if it does not exist yet.
364:             *
365:             * @return the "Export All Types" radio's current value or anticipated initial
366:             *   value
367:             */
368:            public boolean getExportAllTypesValue() {
369:                if (exportAllTypesRadio == null) {
370:                    return initialExportAllTypesValue;
371:                }
372:
373:                return exportAllTypesRadio.getSelection();
374:            }
375:
376:            /**
377:             * Returns the current contents of the resource name entry field,
378:             * or its set initial value if it does not exist yet (which could
379:             * be <code>null</code>).
380:             *
381:             * @return the resource name field's current value or anticipated initial value,
382:             *   or <code>null</code>
383:             */
384:            public String getResourceFieldValue() {
385:                if (resourceNameField == null) {
386:                    return initialExportFieldValue;
387:                }
388:
389:                return resourceNameField.getText();
390:            }
391:
392:            /**
393:             * Return the path for the resource field.
394:             * @return org.eclipse.core.runtime.IPath
395:             */
396:            protected IPath getResourcePath() {
397:                return getPathFromText(this .resourceNameField);
398:            }
399:
400:            /**
401:             * Returns this page's collection of currently-specified resources to be 
402:             * exported. This is the primary resource selection facility accessor for 
403:             * subclasses.
404:             *
405:             * @return the collection of resources currently selected for export (element 
406:             *   type: <code>IResource</code>)
407:             */
408:            protected List getSelectedResources() {
409:                if (selectedResources == null) {
410:                    IResource sourceResource = getSourceResource();
411:
412:                    if (sourceResource != null) {
413:                        selectAppropriateResources(sourceResource);
414:                    }
415:                }
416:
417:                return selectedResources;
418:            }
419:
420:            /**
421:             * Returns the resource object specified in the resource name entry field,
422:             * or <code>null</code> if such a resource does not exist in the workbench.
423:             *
424:             * @return the resource specified in the resource name entry field, or 
425:             *   <code>null</code>
426:             */
427:            protected IResource getSourceResource() {
428:                IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
429:                //make the path absolute to allow for optional leading slash
430:                IPath testPath = getResourcePath();
431:
432:                IStatus result = workspace.validatePath(testPath.toString(),
433:                        IResource.ROOT | IResource.PROJECT | IResource.FOLDER
434:                                | IResource.FILE);
435:
436:                if (result.isOK() && workspace.getRoot().exists(testPath)) {
437:                    return workspace.getRoot().findMember(testPath);
438:                }
439:
440:                return null;
441:            }
442:
443:            /**
444:             * Returns the current contents of the types entry field, or its set
445:             * initial value if it does not exist yet (which could be <code>null</code>).
446:             *
447:             * @return the types entry field's current value or anticipated initial value,
448:             *   or <code>null</code>
449:             */
450:            public String getTypesFieldValue() {
451:                if (typesToExportField == null) {
452:                    return initialTypesFieldValue;
453:                }
454:
455:                return typesToExportField.getText();
456:            }
457:
458:            /**
459:             * Returns the resource extensions currently specified to be exported.
460:             *
461:             * @return the resource extensions currently specified to be exported (element 
462:             *   type: <code>String</code>)
463:             */
464:            protected List getTypesToExport() {
465:                List result = new ArrayList();
466:                StringTokenizer tokenizer = new StringTokenizer(
467:                        typesToExportField.getText(), TYPE_DELIMITER);
468:
469:                while (tokenizer.hasMoreTokens()) {
470:                    String currentExtension = tokenizer.nextToken().trim();
471:                    if (!currentExtension.equals("")) { //$NON-NLS-1$
472:                        result.add(currentExtension);
473:                    }
474:                }
475:
476:                return result;
477:            }
478:
479:            /**
480:             * The <code>WizardExportPage</code> implementation of this 
481:             * <code>Listener</code> method handles all events and enablements for controls
482:             * on this page. Subclasses may extend.
483:             */
484:            public void handleEvent(Event event) {
485:                Widget source = event.widget;
486:
487:                if (source == exportAllTypesRadio
488:                        || source == typesToExportField
489:                        || source == resourceNameField) {
490:                    resetSelectedResources();
491:                } else if (source == exportSpecifiedTypesRadio) {
492:                    resetSelectedResources();
493:                    typesToExportField.setFocus();
494:                } else if (source == resourceDetailsButton) {
495:                    handleResourceDetailsButtonPressed();
496:                } else if (source == resourceBrowseButton) {
497:                    handleResourceBrowseButtonPressed();
498:                } else if (source == typesToExportEditButton) {
499:                    handleTypesEditButtonPressed();
500:                }
501:
502:                setPageComplete(determinePageCompletion());
503:                updateWidgetEnablements();
504:            }
505:
506:            /**
507:             * Opens a container selection dialog and displays the user's subsequent
508:             * container selection in this page's resource name field.
509:             */
510:            protected void handleResourceBrowseButtonPressed() {
511:                IResource currentFolder = getSourceResource();
512:                if (currentFolder != null
513:                        && currentFolder.getType() == IResource.FILE) {
514:                    currentFolder = currentFolder.getParent();
515:                }
516:
517:                IPath containerPath = queryForContainer(
518:                        (IContainer) currentFolder,
519:                        IDEWorkbenchMessages.WizardExportPage_selectResourcesToExport);
520:                if (containerPath != null) { // null means user cancelled
521:                    String relativePath = containerPath.makeRelative()
522:                            .toString();
523:                    if (!relativePath.toString().equals(
524:                            resourceNameField.getText())) {
525:                        resetSelectedResources();
526:                        resourceNameField.setText(relativePath);
527:                    }
528:                }
529:            }
530:
531:            /**
532:             * Opens a resource selection dialog and records the user's subsequent
533:             * resource selections.
534:             */
535:            protected void handleResourceDetailsButtonPressed() {
536:                IAdaptable source = getSourceResource();
537:
538:                if (source == null) {
539:                    source = ResourcesPlugin.getWorkspace().getRoot();
540:                }
541:
542:                selectAppropriateResources(source);
543:
544:                if (source instanceof  IFile) {
545:                    source = ((IFile) source).getParent();
546:                    setResourceToDisplay((IResource) source);
547:                }
548:
549:                Object[] newlySelectedResources = queryIndividualResourcesToExport(source);
550:
551:                if (newlySelectedResources != null) {
552:                    selectedResources = Arrays.asList(newlySelectedResources);
553:                    displayResourcesSelectedCount(selectedResources.size());
554:                }
555:            }
556:
557:            /**
558:             * Queries the user for the types of resources to be exported and
559:             * displays these types in this page's "Types to export" field.
560:             */
561:            protected void handleTypesEditButtonPressed() {
562:                Object[] newSelectedTypes = queryResourceTypesToExport();
563:
564:                if (newSelectedTypes != null) { // ie.- did not press Cancel
565:                    List result = new ArrayList(newSelectedTypes.length);
566:                    for (int i = 0; i < newSelectedTypes.length; i++) {
567:                        result.add(((IFileEditorMapping) newSelectedTypes[i])
568:                                .getExtension());
569:                    }
570:                    setTypesToExport(result);
571:                }
572:            }
573:
574:            /**
575:             * Returns whether the extension of the given resource name is an extension that
576:             * has been specified for export by the user.
577:             *
578:             * @param resourceName the resource name
579:             * @return <code>true</code> if the resource name is suitable for export based 
580:             *   upon its extension
581:             */
582:            protected boolean hasExportableExtension(String resourceName) {
583:                if (selectedTypes == null) {
584:                    return true;
585:                }
586:
587:                int separatorIndex = resourceName.lastIndexOf(".");//$NON-NLS-1$
588:                if (separatorIndex == -1) {
589:                    return false;
590:                }
591:
592:                String extension = resourceName.substring(separatorIndex + 1);
593:
594:                Iterator it = selectedTypes.iterator();
595:                while (it.hasNext()) {
596:                    if (extension.equalsIgnoreCase((String) it.next())) {
597:                        return true;
598:                    }
599:                }
600:
601:                return false;
602:            }
603:
604:            /**
605:             * Persists additional setting that are to be restored in the next instance of
606:             * this page.
607:             * <p> 
608:             * The <code>WizardImportPage</code> implementation of this method does
609:             * nothing. Subclasses may extend to persist additional settings.
610:             * </p>
611:             */
612:            protected void internalSaveWidgetValues() {
613:            }
614:
615:            /**
616:             * Queries the user for the individual resources that are to be exported
617:             * and returns these resources as a collection.
618:             * 
619:             * @param rootResource the resource to use as the root of the selection query
620:             * @return the resources selected for export (element type: 
621:             *   <code>IResource</code>), or <code>null</code> if the user canceled the 
622:             *   selection
623:             */
624:            protected Object[] queryIndividualResourcesToExport(
625:                    IAdaptable rootResource) {
626:                ResourceSelectionDialog dialog = new ResourceSelectionDialog(
627:                        getContainer().getShell(),
628:                        rootResource,
629:                        IDEWorkbenchMessages.WizardExportPage_selectResourcesTitle);
630:                dialog.setInitialSelections(selectedResources
631:                        .toArray(new Object[selectedResources.size()]));
632:                dialog.open();
633:                return dialog.getResult();
634:            }
635:
636:            /**
637:             * Queries the user for the resource types that are to be exported and returns
638:             * these types as a collection.
639:             *
640:             * @return the resource types selected for export (element type: 
641:             *   <code>String</code>), or <code>null</code> if the user canceled the 
642:             *   selection
643:             */
644:            protected Object[] queryResourceTypesToExport() {
645:                IFileEditorMapping editorMappings[] = PlatformUI.getWorkbench()
646:                        .getEditorRegistry().getFileEditorMappings();
647:
648:                int mappingsSize = editorMappings.length;
649:                List selectedTypes = getTypesToExport();
650:                List initialSelections = new ArrayList(selectedTypes.size());
651:
652:                for (int i = 0; i < mappingsSize; i++) {
653:                    IFileEditorMapping currentMapping = editorMappings[i];
654:                    if (selectedTypes.contains(currentMapping.getExtension())) {
655:                        initialSelections.add(currentMapping);
656:                    }
657:                }
658:
659:                ListSelectionDialog dialog = new ListSelectionDialog(
660:                        getContainer().getShell(),
661:                        editorMappings,
662:                        FileEditorMappingContentProvider.INSTANCE,
663:                        FileEditorMappingLabelProvider.INSTANCE,
664:                        IDEWorkbenchMessages.WizardExportPage_selectionDialogMessage);
665:
666:                dialog
667:                        .setTitle(IDEWorkbenchMessages.WizardExportPage_resourceTypeDialog);
668:                dialog.open();
669:
670:                return dialog.getResult();
671:            }
672:
673:            /**
674:             * Resets this page's selected resources collection and updates its controls
675:             * accordingly.
676:             */
677:            protected void resetSelectedResources() {
678:                resourceDetailsDescription
679:                        .setText(IDEWorkbenchMessages.WizardExportPage_detailsMessage);
680:                selectedResources = null;
681:
682:                if (exportCurrentSelection) {
683:                    exportCurrentSelection = false;
684:
685:                    if (resourceNameField.getText().length() > CURRENT_SELECTION
686:                            .length()) {
687:                        resourceNameField.setText(resourceNameField.getText()
688:                                .substring(CURRENT_SELECTION.length()));
689:                    } else {
690:                        resourceNameField.setText("");//$NON-NLS-1$
691:                    }
692:                }
693:            }
694:
695:            /**
696:             * Restores resource specification control settings that were persisted
697:             * in the previous instance of this page. Subclasses wishing to restore
698:             * persisted values for their controls may extend.
699:             */
700:            protected void restoreResourceSpecificationWidgetValues() {
701:                IDialogSettings settings = getDialogSettings();
702:                if (settings != null) {
703:                    String pageName = getName();
704:                    boolean exportAllResources = settings
705:                            .getBoolean(STORE_EXPORT_ALL_RESOURCES_ID
706:                                    + pageName);
707:
708:                    // restore all/typed radio values iff not already explicitly set
709:                    if (!exportAllResourcesPreSet) {
710:                        exportAllTypesRadio.setSelection(exportAllResources);
711:                        exportSpecifiedTypesRadio
712:                                .setSelection(!exportAllResources);
713:                    }
714:
715:                    // restore selected types iff not explicitly already set
716:                    if (initialTypesFieldValue == null) {
717:                        String[] selectedTypes = settings
718:                                .getArray(STORE_SELECTED_TYPES_ID + pageName);
719:                        if (selectedTypes != null) {
720:                            if (selectedTypes.length > 0) {
721:                                typesToExportField.setText(selectedTypes[0]);
722:                            }
723:                            for (int i = 0; i < selectedTypes.length; i++) {
724:                                typesToExportField.add(selectedTypes[i]);
725:                            }
726:                        }
727:                    }
728:                }
729:            }
730:
731:            /**
732:             * Persists resource specification control setting that are to be restored
733:             * in the next instance of this page. Subclasses wishing to persist additional
734:             * setting for their controls should extend hook method 
735:             * <code>internalSaveWidgetValues</code>.
736:             */
737:            protected void saveWidgetValues() {
738:                IDialogSettings settings = getDialogSettings();
739:                if (settings != null) {
740:                    String pageName = getName();
741:
742:                    // update specific types to export history
743:                    String[] selectedTypesNames = settings
744:                            .getArray(STORE_SELECTED_TYPES_ID + pageName);
745:                    if (selectedTypesNames == null) {
746:                        selectedTypesNames = new String[0];
747:                    }
748:
749:                    if (exportSpecifiedTypesRadio.getSelection()) {
750:                        selectedTypesNames = addToHistory(selectedTypesNames,
751:                                typesToExportField.getText());
752:                    }
753:
754:                    settings.put(STORE_SELECTED_TYPES_ID + pageName,
755:                            selectedTypesNames);
756:
757:                    // radio buttons
758:                    settings.put(STORE_EXPORT_ALL_RESOURCES_ID + pageName,
759:                            exportAllTypesRadio.getSelection());
760:                }
761:
762:                // allow subclasses to save values
763:                internalSaveWidgetValues();
764:
765:            }
766:
767:            /**
768:             * Records a container's recursive file descendents which have an extension
769:             * that has been specified for export by the user.
770:             *
771:             * @param resource the parent container
772:             */
773:            protected void selectAppropriateFolderContents(IContainer resource) {
774:                try {
775:                    IResource[] members = resource.members();
776:
777:                    for (int i = 0; i < members.length; i++) {
778:                        if (members[i].getType() == IResource.FILE) {
779:                            IFile currentFile = (IFile) members[i];
780:                            if (hasExportableExtension(currentFile
781:                                    .getFullPath().toString())) {
782:                                selectedResources.add(currentFile);
783:                            }
784:                        }
785:                        if (members[i].getType() == IResource.FOLDER) {
786:                            selectAppropriateFolderContents((IContainer) members[i]);
787:                        }
788:                    }
789:                } catch (CoreException e) {
790:                    //don't show children if there are errors -- should at least log this
791:                }
792:            }
793:
794:            /**
795:             * Records a resource's recursive descendents which are appropriate
796:             * for export based upon this page's current controls contents.
797:             *
798:             * @param resource the parent resource
799:             */
800:            protected void selectAppropriateResources(Object resource) {
801:                if (selectedResources == null) {
802:
803:                    if (exportSpecifiedTypesRadio.getSelection()) {
804:                        selectedTypes = getTypesToExport();
805:                    } else {
806:                        selectedTypes = null; // sentinel for select all extensions
807:                    }
808:
809:                    selectedResources = new ArrayList();
810:                    if (resource instanceof  IWorkspaceRoot) {
811:                        IProject[] projects = ((IWorkspaceRoot) resource)
812:                                .getProjects();
813:                        for (int i = 0; i < projects.length; i++) {
814:                            selectAppropriateFolderContents(projects[i]);
815:                        }
816:                    } else if (resource instanceof  IFile) {
817:                        IFile file = (IFile) resource;
818:                        if (hasExportableExtension(file.getFullPath()
819:                                .toString())) {
820:                            selectedResources.add(file);
821:                        }
822:                    } else {
823:                        selectAppropriateFolderContents((IContainer) resource);
824:                    }
825:                }
826:            }
827:
828:            /**
829:             * Sets the selection value of this page's "Export all types" radio, or stores
830:             * it for future use if this visual component does not exist yet.
831:             *
832:             * @param value new selection value
833:             */
834:            public void setExportAllTypesValue(boolean value) {
835:                if (exportAllTypesRadio == null) {
836:                    initialExportAllTypesValue = value;
837:                    exportAllResourcesPreSet = true;
838:                } else {
839:                    exportAllTypesRadio.setSelection(value);
840:                    exportSpecifiedTypesRadio.setSelection(!value);
841:                }
842:            }
843:
844:            /**
845:             * Sets the value of this page's source resource field, or stores
846:             * it for future use if this visual component does not exist yet.
847:             *
848:             * @param value new value
849:             */
850:            public void setResourceFieldValue(String value) {
851:                if (resourceNameField == null) {
852:                    initialExportFieldValue = value;
853:                } else {
854:                    resourceNameField.setText(value);
855:                }
856:            }
857:
858:            /**
859:             * Set the resource whos name we will display.
860:             * @param resource
861:             */
862:            protected void setResourceToDisplay(IResource resource) {
863:                setResourceFieldValue(resource.getFullPath().makeRelative()
864:                        .toString());
865:            }
866:
867:            /**
868:             * Sets the value of this page's "Types to export" field, or stores
869:             * it for future use if this visual component does not exist yet.
870:             *
871:             * @param value new value
872:             */
873:            public void setTypesFieldValue(String value) {
874:                if (typesToExportField == null) {
875:                    initialTypesFieldValue = value;
876:                } else {
877:                    typesToExportField.setText(value);
878:                }
879:            }
880:
881:            /**
882:             * Sets the value of this page's "Types to export" field based upon the
883:             * collection of extensions.
884:             *
885:             * @param typeStrings the collection of extensions to populate the "Types to
886:             *   export" field with (element type: <code>String</code>)
887:             */
888:            protected void setTypesToExport(List typeStrings) {
889:                StringBuffer result = new StringBuffer();
890:                Iterator typesEnum = typeStrings.iterator();
891:
892:                while (typesEnum.hasNext()) {
893:                    result.append(typesEnum.next());
894:                    result.append(TYPE_DELIMITER);
895:                    result.append(" ");//$NON-NLS-1$
896:                }
897:
898:                typesToExportField.setText(result.toString());
899:            }
900:
901:            /**
902:             * Populates the resource name field based upon the currently selected resources.
903:             */
904:            protected void setupBasedOnInitialSelections() {
905:                if (initialExportFieldValue != null) {
906:                    // a source resource has been programatically specified, which overrides
907:                    // the current workbench resource selection
908:                    IResource specifiedSourceResource = getSourceResource();
909:                    if (specifiedSourceResource == null) {
910:                        currentResourceSelection = new StructuredSelection();
911:                    } else {
912:                        currentResourceSelection = new StructuredSelection(
913:                                specifiedSourceResource);
914:                    }
915:                }
916:
917:                if (currentResourceSelection.isEmpty()) {
918:                    return; // no setup needed
919:                }
920:
921:                List selections = new ArrayList();
922:                Iterator it = currentResourceSelection.iterator();
923:                while (it.hasNext()) {
924:                    IResource currentResource = (IResource) it.next();
925:                    // do not add inaccessible elements
926:                    if (currentResource.isAccessible()) {
927:                        selections.add(currentResource);
928:                    }
929:                }
930:
931:                if (selections.isEmpty()) {
932:                    return; // setup not needed anymore
933:                }
934:
935:                int selectedResourceCount = selections.size();
936:                if (selectedResourceCount == 1) {
937:                    IResource resource = (IResource) selections.get(0);
938:                    setResourceToDisplay(resource);
939:                } else {
940:                    selectedResources = selections;
941:                    exportAllTypesRadio.setSelection(true);
942:                    exportSpecifiedTypesRadio.setSelection(false);
943:                    resourceNameField.setText(CURRENT_SELECTION);
944:                    exportCurrentSelection = true;
945:                    displayResourcesSelectedCount(selectedResourceCount);
946:                }
947:            }
948:
949:            /**
950:             * Updates the enablements of this page's controls. Subclasses may extend.
951:             */
952:            protected void updateWidgetEnablements() {
953:                if (exportCurrentSelection) {
954:                    resourceDetailsButton.setEnabled(true);
955:                } else {
956:                    IResource resource = getSourceResource();
957:                    resourceDetailsButton.setEnabled(resource != null
958:                            && resource.isAccessible());
959:                }
960:
961:                exportSpecifiedTypesRadio.setEnabled(!exportCurrentSelection);
962:                typesToExportField.setEnabled(exportSpecifiedTypesRadio
963:                        .getSelection());
964:                typesToExportEditButton.setEnabled(exportSpecifiedTypesRadio
965:                        .getSelection());
966:            }
967:
968:            /* (non-Javadoc)
969:             * Method declared on WizardDataTransferPage.
970:             */
971:            protected final boolean validateSourceGroup() {
972:                if (exportCurrentSelection) {
973:                    return true;
974:                }
975:
976:                String sourceString = resourceNameField.getText();
977:                if (sourceString.equals("")) {//$NON-NLS-1$
978:                    setErrorMessage(null);
979:                    return false;
980:                }
981:
982:                IResource resource = getSourceResource();
983:
984:                if (resource == null) {
985:                    setErrorMessage(IDEWorkbenchMessages.WizardExportPage_mustExistMessage);
986:                    return false;
987:                }
988:
989:                if (!resource.isAccessible()) {
990:                    setErrorMessage(IDEWorkbenchMessages.WizardExportPage_mustBeAccessibleMessage);
991:                    return false;
992:                }
993:
994:                return true;
995:            }
996:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.