001: /*
002: * Created on 4-Oct-2004 TODO To change the template for this generated file go to Window - Preferences - Java - Code
003: * Style - Code Templates
004: */
005: package net.refractions.udig.project.ui.internal;
006:
007: import java.io.IOException;
008: import java.util.Iterator;
009: import java.util.List;
010:
011: import net.refractions.udig.catalog.IGeoResource;
012: import net.refractions.udig.catalog.IService;
013: import net.refractions.udig.catalog.ui.CatalogTreeViewer;
014: import net.refractions.udig.project.internal.ProjectFactory;
015:
016: import org.eclipse.core.runtime.IStatus;
017: import org.eclipse.core.runtime.Status;
018: import org.eclipse.jface.viewers.ISelectionChangedListener;
019: import org.eclipse.jface.viewers.IStructuredSelection;
020: import org.eclipse.jface.viewers.SelectionChangedEvent;
021: import org.eclipse.jface.wizard.IWizardPage;
022: import org.eclipse.jface.wizard.WizardPage;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.layout.GridLayout;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Label;
028:
029: /**
030: * @author Richard Gould TODO To change the template for this generated type comment go to Window -
031: * Preferences - Java - Code Style - Code Templates
032: */
033: public class SelectLayersPage extends WizardPage implements
034: ISelectionChangedListener {
035:
036: private net.refractions.udig.catalog.ui.CatalogTreeViewer layers;
037: private IStructuredSelection selection;
038:
039: List layerRefs;
040:
041: protected SelectLayersPage() {
042: super (Messages.SelectLayersPage_page_title);
043: this .setDescription(Messages.SelectLayersPage_page_description);
044: }
045:
046: /**
047: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
048: */
049: public void createControl(Composite parent) {
050: Composite composite = new Composite(parent, SWT.NULL);
051:
052: GridLayout gridLayout = new GridLayout(2, false);
053: composite.setLayout(gridLayout);
054:
055: Label label = new Label(composite, SWT.NONE);
056: label
057: .setText(Messages.SelectLayersPage_label_selectLayers_text);
058: label
059: .setLayoutData(new GridData(SWT.END, SWT.TOP, false,
060: false));
061: label
062: .setToolTipText(Messages.SelectLayersPage_label_selectLayers_tooltip);
063:
064: layers = new CatalogTreeViewer(composite);
065: layers.getControl().setLayoutData(
066: new GridData(SWT.FILL, SWT.FILL, true, true));
067: layers.addSelectionChangedListener(this );
068:
069: setControl(composite);
070: setPageComplete(true);
071: }
072:
073: /**
074: * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
075: */
076: public void selectionChanged(SelectionChangedEvent event) {
077: selection = (IStructuredSelection) event.getSelection();
078:
079: getWizard().getContainer().updateButtons();
080: }
081:
082: /**
083: * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
084: */
085: public boolean canFlipToNextPage() {
086: return isPageComplete();
087: }
088:
089: /**
090: * @see org.eclipse.jface.wizard.WizardPage#isPageComplete()
091: */
092: public boolean isPageComplete() {
093: if (selection == null || selection.isEmpty()) {
094: return false;
095: }
096:
097: Iterator iter = selection.iterator();
098: while (iter.hasNext()) {
099: Object object = iter.next();
100: if ((object instanceof IService)
101: || (object instanceof IGeoResource)) {
102: return true;
103: }
104: }
105:
106: return false;
107: }
108:
109: /**
110: * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
111: */
112: public IWizardPage getNextPage() {
113: if (((NewLayerWizard) getWizard()).selectStylePage == null) {
114: ((NewLayerWizard) getWizard()).selectStylePage = new MapStylePage(
115: getLayerRefs());
116: ((NewLayerWizard) getWizard())
117: .addPage(((NewLayerWizard) getWizard()).selectStylePage);
118: }
119: return ((NewLayerWizard) getWizard()).selectStylePage;
120: }
121:
122: List getLayerRefs() {
123: if (layerRefs == null)
124: try {
125: layerRefs = ProjectFactory.eINSTANCE
126: .createLayerFactory().getLayers(
127: selection.toList());
128: } catch (IOException e) {
129: // fall through
130: ProjectUIPlugin
131: .getDefault()
132: .getLog()
133: .log(
134: new Status(
135: IStatus.WARNING,
136: "net.refractions.udig.project.ui", 0, "", e)); //$NON-NLS-1$ //$NON-NLS-2$
137: }
138: return layerRefs;
139: }
140: }
|