001: package net.refractions.udig.project.ui.internal;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import net.refractions.udig.catalog.IGeoResource;
007: import net.refractions.udig.catalog.IService;
008: import net.refractions.udig.catalog.internal.ui.CatalogImport;
009: import net.refractions.udig.catalog.internal.ui.ResourceSelectionPage;
010: import net.refractions.udig.catalog.ui.workflow.DataSourceSelectionState;
011: import net.refractions.udig.catalog.ui.workflow.ResourceSelectionState;
012: import net.refractions.udig.catalog.ui.workflow.Workflow;
013: import net.refractions.udig.catalog.ui.workflow.WorkflowWizard;
014: import net.refractions.udig.catalog.ui.workflow.WorkflowWizardPage;
015: import net.refractions.udig.catalog.ui.workflow.Workflow.State;
016: import net.refractions.udig.project.ui.ApplicationGIS;
017:
018: import org.eclipse.core.runtime.IProgressMonitor;
019:
020: public class MapImport extends CatalogImport {
021:
022: private int layerPosition = -1;
023:
024: public void setLayerPosition(int layerPosition) {
025: this .layerPosition = layerPosition;
026: }
027:
028: @Override
029: protected Workflow createWorkflow() {
030: DataSourceSelectionState dsState = new DataSourceSelectionState(
031: true);
032: ResourceSelectionState rsState = new ResourceSelectionState();
033:
034: Workflow workflow = new Workflow(new Workflow.State[] {
035: dsState, rsState });
036: return workflow;
037: }
038:
039: @Override
040: protected java.util.Map<Class<? extends State>, WorkflowWizardPage> createPageMapping() {
041: java.util.Map<Class<? extends State>, WorkflowWizardPage> map = super
042: .createPageMapping();
043: map.put(ResourceSelectionState.class,
044: new ResourceSelectionPage(
045: Messages.MapImport_selectLayers, null));
046:
047: return map;
048: }
049:
050: @Override
051: protected WorkflowWizard createWorkflowWizard(
052: Workflow workflow,
053: java.util.Map<Class<? extends State>, WorkflowWizardPage> map) {
054: return new MapImportWizard(workflow, map);
055: }
056:
057: protected class MapImportWizard extends
058: CatalogImport.CatalogImportWizard {
059:
060: public MapImportWizard(
061: Workflow workflow,
062: java.util.Map<Class<? extends State>, WorkflowWizardPage> map) {
063: super (workflow, map);
064: }
065:
066: @Override
067: public boolean canFinish() {
068: return super .canFinish();
069: }
070:
071: @Override
072: protected boolean performFinish(IProgressMonitor monitor) {
073: String name = Messages.MapImport_createMap;
074: monitor.beginTask(name, IProgressMonitor.UNKNOWN);
075: monitor.setTaskName(name);
076: boolean super Finished = super .performFinish(monitor);
077: if (!super Finished)
078: return super Finished;
079:
080: ResourceSelectionState state = getWorkflow().getState(
081: ResourceSelectionState.class);
082: java.util.Map<IGeoResource, IService> resourceMap = state
083: .getResources();
084:
085: if (resourceMap == null || resourceMap.isEmpty())
086: return false;
087:
088: // add the resources to the map
089: List<IGeoResource> resourceList = new ArrayList<IGeoResource>(
090: resourceMap.keySet());
091:
092: monitor.setTaskName(Messages.MapImport_addingLayersTask);
093: ApplicationGIS.addLayersToMap(
094: ApplicationGIS.getActiveMap(), resourceList,
095: layerPosition, null, true);
096:
097: return true;
098: }
099:
100: @Override
101: protected boolean isShowCatalogView() {
102: return false;
103: }
104: }
105:
106: }
|