Source Code Cross Referenced for NewWizardNewPage.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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 workbench » org.eclipse.ui.internal.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.internal.dialogs;
011:
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.HashMap;
015:        import java.util.Hashtable;
016:        import java.util.Iterator;
017:        import java.util.List;
018:        import java.util.Map;
019:
020:        import org.eclipse.core.runtime.CoreException;
021:        import org.eclipse.core.runtime.Path;
022:        import org.eclipse.jface.dialogs.Dialog;
023:        import org.eclipse.jface.dialogs.IDialogSettings;
024:        import org.eclipse.jface.resource.ImageDescriptor;
025:        import org.eclipse.jface.viewers.DoubleClickEvent;
026:        import org.eclipse.jface.viewers.IDoubleClickListener;
027:        import org.eclipse.jface.viewers.ISelectionChangedListener;
028:        import org.eclipse.jface.viewers.IStructuredSelection;
029:        import org.eclipse.jface.viewers.SelectionChangedEvent;
030:        import org.eclipse.jface.viewers.StructuredSelection;
031:        import org.eclipse.jface.viewers.TreeViewer;
032:        import org.eclipse.jface.viewers.ViewerFilter;
033:        import org.eclipse.jface.wizard.IWizardContainer;
034:        import org.eclipse.jface.wizard.IWizardContainer2;
035:        import org.eclipse.swt.SWT;
036:        import org.eclipse.swt.custom.CLabel;
037:        import org.eclipse.swt.events.DisposeEvent;
038:        import org.eclipse.swt.events.DisposeListener;
039:        import org.eclipse.swt.events.SelectionAdapter;
040:        import org.eclipse.swt.events.SelectionEvent;
041:        import org.eclipse.swt.graphics.Font;
042:        import org.eclipse.swt.graphics.Image;
043:        import org.eclipse.swt.layout.GridData;
044:        import org.eclipse.swt.layout.GridLayout;
045:        import org.eclipse.swt.widgets.Button;
046:        import org.eclipse.swt.widgets.Composite;
047:        import org.eclipse.swt.widgets.Control;
048:        import org.eclipse.swt.widgets.Label;
049:        import org.eclipse.ui.IWorkbenchWizard;
050:        import org.eclipse.ui.activities.WorkbenchActivityHelper;
051:        import org.eclipse.ui.dialogs.FilteredTree;
052:        import org.eclipse.ui.internal.WorkbenchMessages;
053:        import org.eclipse.ui.model.AdaptableList;
054:        import org.eclipse.ui.model.WorkbenchLabelProvider;
055:        import org.eclipse.ui.wizards.IWizardCategory;
056:        import org.eclipse.ui.wizards.IWizardDescriptor;
057:
058:        /**
059:         * New wizard selection tab that allows the user to select a registered 'New'
060:         * wizard to be launched.
061:         */
062:        class NewWizardNewPage implements  ISelectionChangedListener {
063:
064:            // id constants
065:            private static final String DIALOG_SETTING_SECTION_NAME = "NewWizardSelectionPage."; //$NON-NLS-1$
066:
067:            private final static int SIZING_LISTS_HEIGHT = 200;
068:
069:            private final static int SIZING_VIEWER_WIDTH = 300;
070:
071:            private final static String STORE_EXPANDED_CATEGORIES_ID = DIALOG_SETTING_SECTION_NAME
072:                    + "STORE_EXPANDED_CATEGORIES_ID"; //$NON-NLS-1$
073:
074:            private final static String STORE_SELECTED_ID = DIALOG_SETTING_SECTION_NAME
075:                    + "STORE_SELECTED_ID"; //$NON-NLS-1$
076:
077:            private NewWizardSelectionPage page;
078:
079:            private FilteredTree filteredTree;
080:
081:            private WizardPatternFilter filteredTreeFilter;
082:
083:            //Keep track of the wizards we have previously selected
084:            private Hashtable selectedWizards = new Hashtable();
085:
086:            private IDialogSettings settings;
087:
088:            private Button showAllCheck;
089:
090:            private IWizardCategory wizardCategories;
091:
092:            private IWizardDescriptor[] primaryWizards;
093:
094:            private CLabel descImageCanvas;
095:
096:            private Map imageTable = new HashMap();
097:
098:            private IWizardDescriptor selectedElement;
099:
100:            private WizardActivityFilter filter = new WizardActivityFilter();
101:
102:            private boolean needShowAll;
103:
104:            private boolean projectsOnly;
105:
106:            private ViewerFilter projectFilter = new WizardTagFilter(
107:                    new String[] { WorkbenchWizardElement.TAG_PROJECT });
108:
109:            /**
110:             * Create an instance of this class
111:             * @param mainPage 
112:             * @param wizardCategories 
113:             * @param primaryWizards 
114:             * @param projectsOnly 
115:             */
116:            public NewWizardNewPage(NewWizardSelectionPage mainPage,
117:                    IWizardCategory wizardCategories,
118:                    IWizardDescriptor[] primaryWizards, boolean projectsOnly) {
119:                this .page = mainPage;
120:                this .wizardCategories = wizardCategories;
121:                this .primaryWizards = primaryWizards;
122:                this .projectsOnly = projectsOnly;
123:
124:                trimPrimaryWizards();
125:
126:                if (this .primaryWizards.length > 0) {
127:                    if (allPrimary(wizardCategories)) {
128:                        this .wizardCategories = null; // dont bother considering the categories as all wizards are primary
129:                        needShowAll = false;
130:                    } else {
131:                        needShowAll = !allActivityEnabled(wizardCategories);
132:                    }
133:                } else {
134:                    needShowAll = !allActivityEnabled(wizardCategories);
135:                }
136:            }
137:
138:            /**
139:             * @param category the wizard category
140:             * @return whether all of the wizards in the category are enabled via activity filtering
141:             */
142:            private boolean allActivityEnabled(IWizardCategory category) {
143:                IWizardDescriptor[] wizards = category.getWizards();
144:                for (int i = 0; i < wizards.length; i++) {
145:                    IWizardDescriptor wizard = wizards[i];
146:                    if (WorkbenchActivityHelper.filterItem(wizard)) {
147:                        return false;
148:                    }
149:                }
150:
151:                IWizardCategory[] children = category.getCategories();
152:                for (int i = 0; i < children.length; i++) {
153:                    if (!allActivityEnabled(children[i])) {
154:                        return false;
155:                    }
156:                }
157:
158:                return true;
159:            }
160:
161:            /**
162:             * Remove all primary wizards that are not in the wizard collection
163:             */
164:            private void trimPrimaryWizards() {
165:                ArrayList newPrimaryWizards = new ArrayList(
166:                        primaryWizards.length);
167:
168:                if (wizardCategories == null) {
169:                    return;//No categories so nothing to trim
170:                }
171:
172:                for (int i = 0; i < primaryWizards.length; i++) {
173:                    if (wizardCategories.findWizard(primaryWizards[i].getId()) != null) {
174:                        newPrimaryWizards.add(primaryWizards[i]);
175:                    }
176:                }
177:
178:                primaryWizards = (WorkbenchWizardElement[]) newPrimaryWizards
179:                        .toArray(new WorkbenchWizardElement[newPrimaryWizards
180:                                .size()]);
181:            }
182:
183:            /**
184:             * @param category the wizard category
185:             * @return whether all wizards in the category are considered primary
186:             */
187:            private boolean allPrimary(IWizardCategory category) {
188:                IWizardDescriptor[] wizards = category.getWizards();
189:                for (int i = 0; i < wizards.length; i++) {
190:                    IWizardDescriptor wizard = wizards[i];
191:                    if (!isPrimary(wizard)) {
192:                        return false;
193:                    }
194:                }
195:
196:                IWizardCategory[] children = category.getCategories();
197:                for (int i = 0; i < children.length; i++) {
198:                    if (!allPrimary(children[i])) {
199:                        return false;
200:                    }
201:                }
202:
203:                return true;
204:            }
205:
206:            /**
207:             * @param wizard
208:             * @return whether the given wizard is primary
209:             */
210:            private boolean isPrimary(IWizardDescriptor wizard) {
211:                for (int j = 0; j < primaryWizards.length; j++) {
212:                    if (primaryWizards[j].equals(wizard)) {
213:                        return true;
214:                    }
215:                }
216:
217:                return false;
218:            }
219:
220:            /**
221:             * @since 3.0
222:             */
223:            public void activate() {
224:                page
225:                        .setDescription(WorkbenchMessages.NewWizardNewPage_description);
226:            }
227:
228:            /**
229:             * Create this tab's visual components
230:             * 
231:             * @param parent Composite
232:             * @return Control
233:             */
234:            protected Control createControl(Composite parent) {
235:
236:                Font wizardFont = parent.getFont();
237:                // top level group
238:                Composite outerContainer = new Composite(parent, SWT.NONE);
239:                GridLayout layout = new GridLayout();
240:                outerContainer.setLayout(layout);
241:
242:                Label wizardLabel = new Label(outerContainer, SWT.NONE);
243:                GridData data = new GridData(SWT.BEGINNING, SWT.FILL, false,
244:                        true);
245:                outerContainer.setLayoutData(data);
246:                wizardLabel.setFont(wizardFont);
247:                wizardLabel
248:                        .setText(WorkbenchMessages.NewWizardNewPage_wizardsLabel);
249:
250:                Composite innerContainer = new Composite(outerContainer,
251:                        SWT.NONE);
252:                layout = new GridLayout(2, false);
253:                layout.marginHeight = 0;
254:                layout.marginWidth = 0;
255:                innerContainer.setLayout(layout);
256:                innerContainer.setFont(wizardFont);
257:                data = new GridData(SWT.FILL, SWT.FILL, true, true);
258:                innerContainer.setLayoutData(data);
259:
260:                filteredTree = createFilteredTree(innerContainer);
261:                createOptionsButtons(innerContainer);
262:
263:                createImage(innerContainer);
264:
265:                updateDescription(null);
266:
267:                // wizard actions pane...create SWT table directly to
268:                // get single selection mode instead of multi selection.
269:                restoreWidgetValues();
270:
271:                return outerContainer;
272:            }
273:
274:            /**
275:             * Create a new FilteredTree in the parent.
276:             * 
277:             * @param parent the parent <code>Composite</code>.
278:             * @since 3.0
279:             */
280:            protected FilteredTree createFilteredTree(Composite parent) {
281:                Composite composite = new Composite(parent, SWT.NONE);
282:                GridLayout layout = new GridLayout();
283:                layout.marginHeight = 0;
284:                layout.marginWidth = 0;
285:                composite.setLayout(layout);
286:
287:                GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
288:                data.widthHint = SIZING_VIEWER_WIDTH;
289:                data.horizontalSpan = 2;
290:                data.grabExcessHorizontalSpace = true;
291:                data.grabExcessVerticalSpace = true;
292:
293:                boolean needsHint = DialogUtil.inRegularFontMode(parent);
294:
295:                //Only give a height hint if the dialog is going to be too small
296:                if (needsHint) {
297:                    data.heightHint = SIZING_LISTS_HEIGHT;
298:                }
299:                composite.setLayoutData(data);
300:
301:                filteredTreeFilter = new WizardPatternFilter();
302:                FilteredTree filterTree = new FilteredTree(composite,
303:                        SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER,
304:                        filteredTreeFilter);
305:
306:                final TreeViewer treeViewer = filterTree.getViewer();
307:                treeViewer.setContentProvider(new WizardContentProvider());
308:                treeViewer.setLabelProvider(new WorkbenchLabelProvider());
309:                treeViewer
310:                        .setComparator(NewWizardCollectionComparator.INSTANCE);
311:                treeViewer.addSelectionChangedListener(this );
312:
313:                ArrayList inputArray = new ArrayList();
314:
315:                for (int i = 0; i < primaryWizards.length; i++) {
316:                    inputArray.add(primaryWizards[i]);
317:                }
318:
319:                boolean expandTop = false;
320:
321:                if (wizardCategories != null) {
322:                    if (wizardCategories.getParent() == null) {
323:                        IWizardCategory[] children = wizardCategories
324:                                .getCategories();
325:                        for (int i = 0; i < children.length; i++) {
326:                            inputArray.add(children[i]);
327:                        }
328:                    } else {
329:                        expandTop = true;
330:                        inputArray.add(wizardCategories);
331:                    }
332:                }
333:
334:                // ensure the category is expanded.  If there is a remembered expansion it will be set later.
335:                if (expandTop) {
336:                    treeViewer.setAutoExpandLevel(2);
337:                }
338:
339:                AdaptableList input = new AdaptableList(inputArray);
340:
341:                treeViewer.setInput(input);
342:
343:                filterTree.setBackground(parent.getDisplay().getSystemColor(
344:                        SWT.COLOR_WIDGET_BACKGROUND));
345:
346:                treeViewer.getTree().setFont(parent.getFont());
347:
348:                treeViewer.addDoubleClickListener(new IDoubleClickListener() {
349:                    /*
350:                     * (non-Javadoc)
351:                     * 
352:                     * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
353:                     */
354:                    public void doubleClick(DoubleClickEvent event) {
355:                        IStructuredSelection s = (IStructuredSelection) event
356:                                .getSelection();
357:                        selectionChanged(new SelectionChangedEvent(event
358:                                .getViewer(), s));
359:
360:                        Object element = s.getFirstElement();
361:                        if (treeViewer.isExpandable(element)) {
362:                            treeViewer.setExpandedState(element, !treeViewer
363:                                    .getExpandedState(element));
364:                        } else if (element instanceof  WorkbenchWizardElement) {
365:                            page.advanceToNextPageOrFinish();
366:                        }
367:                    }
368:                });
369:
370:                treeViewer.addFilter(filter);
371:
372:                if (projectsOnly) {
373:                    treeViewer.addFilter(projectFilter);
374:                }
375:
376:                Dialog.applyDialogFont(filterTree);
377:                return filterTree;
378:            }
379:
380:            /**
381:             * Create the Show All and help buttons at the bottom of the page.
382:             * 
383:             * @param parent the parent composite on which to create the widgets
384:             */
385:            private void createOptionsButtons(Composite parent) {
386:                if (needShowAll) {
387:                    showAllCheck = new Button(parent, SWT.CHECK);
388:                    GridData data = new GridData();
389:                    showAllCheck.setLayoutData(data);
390:                    showAllCheck.setFont(parent.getFont());
391:                    showAllCheck
392:                            .setText(WorkbenchMessages.NewWizardNewPage_showAll);
393:                    showAllCheck.setSelection(false);
394:
395:                    // flipping tabs updates the selected node
396:                    showAllCheck.addSelectionListener(new SelectionAdapter() {
397:
398:                        // the delta of expanded elements between the last 'show all'
399:                        // and the current 'no show all'
400:                        private Object[] delta = new Object[0];
401:
402:                        public void widgetSelected(SelectionEvent e) {
403:                            boolean showAll = showAllCheck.getSelection();
404:
405:                            if (showAll) {
406:                                filteredTree.getViewer().getControl()
407:                                        .setRedraw(false);
408:                            } else {
409:                                // get the inital expanded elements when going from show
410:                                // all-> no show all.
411:                                // this isnt really the delta yet, we're just reusing
412:                                // the variable.
413:                                delta = filteredTree.getViewer()
414:                                        .getExpandedElements();
415:                            }
416:
417:                            try {
418:                                if (showAll) {
419:                                    filteredTree.getViewer().resetFilters();
420:                                    filteredTree.getViewer().addFilter(
421:                                            filteredTreeFilter);
422:                                    if (projectsOnly) {
423:                                        filteredTree.getViewer().addFilter(
424:                                                projectFilter);
425:                                    }
426:
427:                                    // restore the expanded elements that were present
428:                                    // in the last show all state but not in the 'no
429:                                    // show all' state.
430:                                    Object[] currentExpanded = filteredTree
431:                                            .getViewer().getExpandedElements();
432:                                    Object[] expanded = new Object[delta.length
433:                                            + currentExpanded.length];
434:                                    System
435:                                            .arraycopy(currentExpanded, 0,
436:                                                    expanded, 0,
437:                                                    currentExpanded.length);
438:                                    System.arraycopy(delta, 0, expanded,
439:                                            currentExpanded.length,
440:                                            delta.length);
441:                                    filteredTree.getViewer()
442:                                            .setExpandedElements(expanded);
443:                                } else {
444:                                    filteredTree.getViewer().addFilter(filter);
445:                                    if (projectsOnly) {
446:                                        filteredTree.getViewer().addFilter(
447:                                                projectFilter);
448:                                    }
449:                                }
450:                                filteredTree.getViewer().refresh(false);
451:
452:                                if (!showAll) {
453:                                    // if we're going from show all -> no show all
454:                                    // record the elements that were expanded in the
455:                                    // 'show all' state but not the 'no show all' state
456:                                    // (because they didnt exist).
457:                                    Object[] newExpanded = filteredTree
458:                                            .getViewer().getExpandedElements();
459:                                    List deltaList = new ArrayList(Arrays
460:                                            .asList(delta));
461:                                    deltaList.removeAll(Arrays
462:                                            .asList(newExpanded));
463:                                }
464:                            } finally {
465:                                if (showAll) {
466:                                    filteredTree.getViewer().getControl()
467:                                            .setRedraw(true);
468:                                }
469:                            }
470:                        }
471:                    });
472:                }
473:            }
474:
475:            /**
476:             * Create the image controls.
477:             * 
478:             * @param parent the parent <code>Composite</code>.
479:             * @since 3.0
480:             */
481:            private void createImage(Composite parent) {
482:                descImageCanvas = new CLabel(parent, SWT.NONE);
483:                GridData data = new GridData(
484:                        GridData.HORIZONTAL_ALIGN_BEGINNING
485:                                | GridData.VERTICAL_ALIGN_BEGINNING);
486:                data.widthHint = 0;
487:                data.heightHint = 0;
488:                descImageCanvas.setLayoutData(data);
489:
490:                // hook a listener to get rid of cached images.
491:                descImageCanvas.addDisposeListener(new DisposeListener() {
492:
493:                    /* (non-Javadoc)
494:                     * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
495:                     */
496:                    public void widgetDisposed(DisposeEvent e) {
497:                        for (Iterator i = imageTable.values().iterator(); i
498:                                .hasNext();) {
499:                            ((Image) i.next()).dispose();
500:                        }
501:                        imageTable.clear();
502:                    }
503:                });
504:            }
505:
506:            /**
507:             * Expands the wizard categories in this page's category viewer that were
508:             * expanded last time this page was used. If a category that was previously
509:             * expanded no longer exists then it is ignored.
510:             */
511:            protected void expandPreviouslyExpandedCategories() {
512:                String[] expandedCategoryPaths = settings
513:                        .getArray(STORE_EXPANDED_CATEGORIES_ID);
514:                if (expandedCategoryPaths == null
515:                        || expandedCategoryPaths.length == 0) {
516:                    return;
517:                }
518:
519:                List categoriesToExpand = new ArrayList(
520:                        expandedCategoryPaths.length);
521:
522:                if (wizardCategories != null) {
523:                    for (int i = 0; i < expandedCategoryPaths.length; i++) {
524:                        IWizardCategory category = wizardCategories
525:                                .findCategory(new Path(expandedCategoryPaths[i]));
526:                        if (category != null) {
527:                            categoriesToExpand.add(category);
528:                        }
529:                    }
530:                }
531:
532:                if (!categoriesToExpand.isEmpty()) {
533:                    filteredTree.getViewer().setExpandedElements(
534:                            categoriesToExpand.toArray());
535:                }
536:
537:            }
538:
539:            /**
540:             * Returns the single selected object contained in the passed
541:             * selectionEvent, or <code>null</code> if the selectionEvent contains
542:             * either 0 or 2+ selected objects.
543:             */
544:            protected Object getSingleSelection(IStructuredSelection selection) {
545:                return selection.size() == 1 ? selection.getFirstElement()
546:                        : null;
547:            }
548:
549:            /**
550:             * Set self's widgets to the values that they held last time this page was
551:             * open
552:             *  
553:             */
554:            protected void restoreWidgetValues() {
555:                expandPreviouslyExpandedCategories();
556:                selectPreviouslySelected();
557:            }
558:
559:            /**
560:             * Store the current values of self's widgets so that they can be restored
561:             * in the next instance of self
562:             *  
563:             */
564:            public void saveWidgetValues() {
565:                storeExpandedCategories();
566:                storeSelectedCategoryAndWizard();
567:            }
568:
569:            /**
570:             * The user selected either new wizard category(s) or wizard element(s).
571:             * Proceed accordingly.
572:             * 
573:             * @param selectionEvent ISelection
574:             */
575:            public void selectionChanged(SelectionChangedEvent selectionEvent) {
576:                page.setErrorMessage(null);
577:                page.setMessage(null);
578:
579:                Object selectedObject = getSingleSelection((IStructuredSelection) selectionEvent
580:                        .getSelection());
581:
582:                if (selectedObject instanceof  IWizardDescriptor) {
583:                    if (selectedObject == selectedElement) {
584:                        return;
585:                    }
586:                    updateWizardSelection((IWizardDescriptor) selectedObject);
587:                } else {
588:                    selectedElement = null;
589:                    page.setHasPages(false);
590:                    page.setCanFinishEarly(false);
591:                    page.selectWizardNode(null);
592:                    updateDescription(null);
593:                }
594:            }
595:
596:            /**
597:             * Selects the wizard category and wizard in this page that were selected
598:             * last time this page was used. If a category or wizard that was
599:             * previously selected no longer exists then it is ignored.
600:             */
601:            protected void selectPreviouslySelected() {
602:                String selectedId = settings.get(STORE_SELECTED_ID);
603:                if (selectedId == null) {
604:                    return;
605:                }
606:
607:                if (wizardCategories == null) {
608:                    return;
609:                }
610:
611:                Object selected = wizardCategories.findCategory(new Path(
612:                        selectedId));
613:
614:                if (selected == null) {
615:                    selected = wizardCategories.findWizard(selectedId);
616:
617:                    if (selected == null) {
618:                        // if we cant find either a category or a wizard, abort.
619:                        return;
620:                    }
621:                }
622:
623:                //work around for 62039
624:                final StructuredSelection selection = new StructuredSelection(
625:                        selected);
626:                filteredTree.getViewer().getControl().getDisplay().asyncExec(
627:                        new Runnable() {
628:                            public void run() {
629:                                filteredTree.getViewer().setSelection(
630:                                        selection, true);
631:                            }
632:                        });
633:            }
634:
635:            /**
636:             * Set the dialog store to use for widget value storage and retrieval
637:             * 
638:             * @param settings IDialogSettings
639:             */
640:            public void setDialogSettings(IDialogSettings settings) {
641:                this .settings = settings;
642:            }
643:
644:            /**
645:             * Stores the collection of currently-expanded categories in this page's
646:             * dialog store, in order to recreate this page's state in the next
647:             * instance of this page.
648:             */
649:            protected void storeExpandedCategories() {
650:                Object[] expandedElements = filteredTree.getViewer()
651:                        .getExpandedElements();
652:                List expandedElementPaths = new ArrayList(
653:                        expandedElements.length);
654:                for (int i = 0; i < expandedElements.length; ++i) {
655:                    if (expandedElements[i] instanceof  IWizardCategory) {
656:                        expandedElementPaths
657:                                .add(((IWizardCategory) expandedElements[i])
658:                                        .getPath().toString());
659:                    }
660:                }
661:                settings
662:                        .put(
663:                                STORE_EXPANDED_CATEGORIES_ID,
664:                                (String[]) expandedElementPaths
665:                                        .toArray(new String[expandedElementPaths
666:                                                .size()]));
667:            }
668:
669:            /**
670:             * Stores the currently-selected element in this page's dialog store, in
671:             * order to recreate this page's state in the next instance of this page.
672:             */
673:            protected void storeSelectedCategoryAndWizard() {
674:                Object selected = getSingleSelection((IStructuredSelection) filteredTree
675:                        .getViewer().getSelection());
676:
677:                if (selected != null) {
678:                    if (selected instanceof  IWizardCategory) {
679:                        settings.put(STORE_SELECTED_ID,
680:                                ((IWizardCategory) selected).getPath()
681:                                        .toString());
682:                    } else {
683:                        // else its a wizard
684:                        settings.put(STORE_SELECTED_ID,
685:                                ((IWizardDescriptor) selected).getId());
686:                    }
687:                }
688:            }
689:
690:            /**
691:             * Update the current description controls.
692:             * 
693:             * @param selectedObject the new wizard
694:             * @since 3.0
695:             */
696:            private void updateDescription(IWizardDescriptor selectedObject) {
697:                String string = ""; //$NON-NLS-1$
698:                if (selectedObject != null) {
699:                    string = selectedObject.getDescription();
700:                }
701:
702:                page.setDescription(string);
703:
704:                if (hasImage(selectedObject)) {
705:                    ImageDescriptor descriptor = null;
706:                    if (selectedObject != null) {
707:                        descriptor = selectedObject.getDescriptionImage();
708:                    }
709:
710:                    if (descriptor != null) {
711:                        GridData data = (GridData) descImageCanvas
712:                                .getLayoutData();
713:                        data.widthHint = SWT.DEFAULT;
714:                        data.heightHint = SWT.DEFAULT;
715:                        Image image = (Image) imageTable.get(descriptor);
716:                        if (image == null) {
717:                            image = descriptor.createImage(false);
718:                            imageTable.put(descriptor, image);
719:                        }
720:                        descImageCanvas.setImage(image);
721:                    }
722:                } else {
723:                    GridData data = (GridData) descImageCanvas.getLayoutData();
724:                    data.widthHint = 0;
725:                    data.heightHint = 0;
726:                    descImageCanvas.setImage(null);
727:                }
728:
729:                descImageCanvas.getParent().layout(true);
730:
731:                IWizardContainer container = page.getWizard().getContainer();
732:                if (container instanceof  IWizardContainer2) {
733:                    ((IWizardContainer2) container).updateSize();
734:                }
735:            }
736:
737:            /**
738:             * Tests whether the given wizard has an associated image.
739:             * 
740:             * @param selectedObject the wizard to test
741:             * @return whether the given wizard has an associated image
742:             */
743:            private boolean hasImage(IWizardDescriptor selectedObject) {
744:                if (selectedObject == null) {
745:                    return false;
746:                }
747:
748:                if (selectedObject.getDescriptionImage() != null) {
749:                    return true;
750:                }
751:
752:                return false;
753:            }
754:
755:            /**
756:             * @param selectedObject
757:             */
758:            private void updateWizardSelection(IWizardDescriptor selectedObject) {
759:                selectedElement = selectedObject;
760:                WorkbenchWizardNode selectedNode;
761:                if (selectedWizards.containsKey(selectedObject)) {
762:                    selectedNode = (WorkbenchWizardNode) selectedWizards
763:                            .get(selectedObject);
764:                } else {
765:                    selectedNode = new WorkbenchWizardNode(page, selectedObject) {
766:                        public IWorkbenchWizard createWizard()
767:                                throws CoreException {
768:                            return wizardElement.createWizard();
769:                        }
770:                    };
771:                    selectedWizards.put(selectedObject, selectedNode);
772:                }
773:
774:                page.setCanFinishEarly(selectedObject.canFinishEarly());
775:                page.setHasPages(selectedObject.hasPages());
776:                page.selectWizardNode(selectedNode);
777:
778:                updateDescription(selectedObject);
779:            }
780:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.