001: package net.refractions.udig.project.ui.internal;
002:
003: import java.util.List;
004:
005: import net.refractions.udig.project.internal.ContextModel;
006: import net.refractions.udig.project.internal.Layer;
007: import net.refractions.udig.project.internal.Map;
008: import net.refractions.udig.project.internal.Project;
009: import net.refractions.udig.project.internal.ProjectPlugin;
010: import net.refractions.udig.project.internal.render.RenderManager;
011: import net.refractions.udig.project.internal.render.ViewportModel;
012:
013: import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
014: import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
015: import org.eclipse.jface.viewers.ISelectionChangedListener;
016: import org.eclipse.jface.viewers.IStructuredSelection;
017: import org.eclipse.jface.viewers.SelectionChangedEvent;
018: import org.eclipse.jface.viewers.StructuredSelection;
019: import org.eclipse.jface.viewers.TreeViewer;
020: import org.eclipse.jface.wizard.WizardPage;
021: import org.eclipse.swt.SWT;
022: import org.eclipse.swt.layout.GridData;
023: import org.eclipse.swt.layout.GridLayout;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Label;
026:
027: /**
028: * A Wizard page for selecting a map. Part of the New Layer wizard.
029: *
030: * @author Richard Gould
031: */
032: public class SelectMapPage extends WizardPage implements
033: ISelectionChangedListener {
034:
035: Map selectedMap;
036:
037: private TreeViewer tree;
038:
039: private IStructuredSelection selection;
040:
041: protected SelectMapPage() {
042: super (Messages.SelectMapPage_page_title);
043: setDescription(Messages.SelectMapPage_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:
051: Composite composite = new Composite(parent, SWT.NULL);
052:
053: GridLayout gridLayout = new GridLayout(2, false);
054: composite.setLayout(gridLayout);
055:
056: Label label = new Label(composite, SWT.NONE);
057: label.setText(Messages.SelectMapPage_label_selectAMap_text);
058: label
059: .setLayoutData(new GridData(SWT.END, SWT.TOP, false,
060: false));
061: label.setToolTipText(Messages.SelectMapPage_page_description);
062:
063: tree = new TreeViewer(composite, SWT.SINGLE);
064:
065: tree.setAutoExpandLevel(2);
066: tree.setContentProvider(new AdapterFactoryContentProvider(
067: ProjectExplorer.getProjectExplorer()
068: .getAdapterFactory()));
069:
070: tree.setLabelProvider(new AdapterFactoryLabelProvider(
071: ProjectExplorer.getProjectExplorer()
072: .getAdapterFactory()));
073: tree.setInput(ProjectPlugin.getPlugin().getProjectRegistry());
074:
075: tree.getControl().setLayoutData(
076: new GridData(SWT.FILL, SWT.FILL, true, true));
077:
078: tree.addSelectionChangedListener(this );
079:
080: setControl(composite);
081: setPageComplete(true);
082: }
083:
084: /**
085: * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
086: */
087: public void selectionChanged(SelectionChangedEvent event) {
088: selection = (IStructuredSelection) event.getSelection();
089: Object obj = selection.getFirstElement();
090: if (obj instanceof Map) {
091: getWizard().getContainer().updateButtons();
092: return;
093: } else if (obj instanceof Project) {
094: List maps = ((Project) obj).getElements(Map.class);
095: selection = new StructuredSelection(maps.size() > 0 ? maps
096: .get(0) : obj);
097: } else if (obj instanceof ContextModel) {
098: selection = new StructuredSelection(((ContextModel) obj)
099: .getMap());
100: } else if (obj instanceof ViewportModel) {
101: selection = new StructuredSelection(((ViewportModel) obj)
102: .getMapInternal());
103: } else if (obj instanceof RenderManager) {
104: selection = new StructuredSelection(((RenderManager) obj)
105: .getMapInternal());
106: } else if (obj instanceof Layer) {
107: selection = new StructuredSelection(((Layer) obj)
108: .getContextModel().getMap());
109: } else
110: return;
111: tree.setSelection(selection, true);
112: getWizard().getContainer().updateButtons();
113:
114: }
115:
116: /**
117: * @see org.eclipse.jface.wizard.IWizardPage#canFlipToNextPage()
118: */
119: public boolean canFlipToNextPage() {
120: // TODO Auto-generated method stub
121: return isPageComplete();
122: }
123:
124: /**
125: * @see org.eclipse.jface.wizard.IWizardPage#isPageComplete()
126: */
127: public boolean isPageComplete() {
128: if (selection == null) {
129: return false;
130: }
131: if (selection.isEmpty()) {
132: return false;
133: }
134: if (selection.getFirstElement() instanceof Map) {
135: selectedMap = (Map) selection.getFirstElement();
136: System.out.println(selectedMap);
137: return true;
138: }
139: return false;
140: }
141: }
|