01: package net.refractions.udig.catalog.ui.export;
02:
03: import java.io.IOException;
04: import java.util.ArrayList;
05: import java.util.List;
06:
07: import net.refractions.udig.catalog.IGeoResource;
08: import net.refractions.udig.catalog.ui.internal.Messages;
09: import net.refractions.udig.catalog.ui.workflow.Workflow;
10: import net.refractions.udig.core.AdapterUtil;
11: import net.refractions.udig.ui.ProgressManager;
12:
13: import org.eclipse.core.runtime.IProgressMonitor;
14: import org.eclipse.jface.viewers.ISelection;
15: import org.eclipse.jface.viewers.StructuredSelection;
16: import org.eclipse.ui.PlatformUI;
17:
18: public class ExportResourceSelectionState extends Workflow.State {
19:
20: List<Data> layers;
21: List<Data> selectedLayers;
22: ISelection selection = null;
23:
24: /**
25: * The selection to save. Expected value is a map or layers
26: *
27: * @param selection
28: */
29: public ExportResourceSelectionState(ISelection selection) {
30: this .selection = selection;
31: }
32:
33: public ExportResourceSelectionState() {
34: this (null);
35: }
36:
37: public List<Data> getLayers() {
38: return layers;
39: }
40:
41: public List<Data> getSelectedLayers() {
42: return selectedLayers;
43: }
44:
45: public void setSelectedLayers(List<Data> selectedLayers) {
46: this .selectedLayers = selectedLayers;
47: }
48:
49: @Override
50: public void init(IProgressMonitor monitor) throws IOException {
51: super .init(monitor);
52:
53: layers = new ArrayList<Data>();
54:
55: if (selection == null) {
56: selection = PlatformUI.getWorkbench()
57: .getActiveWorkbenchWindow().getActivePage()
58: .getSelection();
59: }
60: Object items[] = new Object[0];
61: if (selection instanceof StructuredSelection) {
62: items = ((StructuredSelection) selection).toArray();
63: }
64:
65: for (int i = 0; i < items.length; i++) {
66: if (items[i] instanceof IGeoResource) {
67: layers.add(new Data((IGeoResource) items[i]));
68: } else {
69:
70: IGeoResource resource = AdapterUtil.instance
71: .getOperationTarget(IGeoResource.class,
72: items[i], ProgressManager.instance()
73: .get());
74: if (resource != null) {
75: layers.add(new Data(resource));
76: }
77: }
78: }
79: }
80:
81: @Override
82: public boolean run(IProgressMonitor monitor) throws IOException {
83: // complete if all the resources have been "selected"
84: if (layers == null || layers.isEmpty()
85: || selectedLayers == null || selectedLayers.isEmpty())
86: return false;
87: return true;
88: }
89:
90: @Override
91: public String getName() {
92: return Messages.CatalogExport_exportLayersTask;
93: }
94:
95: }
|