001: package net.refractions.udig.mapgraphic.internal.ui;
002:
003: import java.io.Serializable;
004: import java.lang.reflect.InvocationTargetException;
005: import java.net.URL;
006: import java.util.ArrayList;
007: import java.util.List;
008: import java.util.Map;
009:
010: import net.refractions.udig.catalog.CatalogPlugin;
011: import net.refractions.udig.catalog.IService;
012: import net.refractions.udig.catalog.IServiceFactory;
013: import net.refractions.udig.catalog.ui.UDIGConnectionPage;
014: import net.refractions.udig.catalog.ui.workflow.WorkflowWizard;
015: import net.refractions.udig.mapgraphic.MapGraphicPlugin;
016: import net.refractions.udig.mapgraphic.internal.MapGraphicService;
017: import net.refractions.udig.mapgraphic.internal.Messages;
018:
019: import org.eclipse.core.runtime.IProgressMonitor;
020: import org.eclipse.jface.operation.IRunnableWithProgress;
021: import org.eclipse.jface.wizard.IWizard;
022: import org.eclipse.jface.wizard.WizardPage;
023: import org.eclipse.swt.SWT;
024: import org.eclipse.swt.widgets.Composite;
025: import org.eclipse.swt.widgets.Display;
026:
027: public class MapGraphicWizardPage extends WizardPage implements
028: UDIGConnectionPage {
029:
030: public static final String ID = "net.refractions.udig.mapgraphic.wizardPageId"; //$NON-NLS-1$
031:
032: public MapGraphicWizardPage() {
033: super (Messages.MapGraphic_title);
034: }
035:
036: public List<IService> getResources(IProgressMonitor monitor)
037: throws Exception {
038: IServiceFactory factory = CatalogPlugin.getDefault()
039: .getServiceFactory();
040: List<IService> services = factory
041: .acquire(MapGraphicService.SERVICE_URL);
042:
043: return services;
044: }
045:
046: public String getId() {
047: return ID;
048: }
049:
050: public Map<String, Serializable> getParams() {
051: return null;
052: }
053:
054: public List<URL> getURLs() {
055: ArrayList<URL> l = new ArrayList<URL>();
056: l.add(MapGraphicService.SERVICE_URL);
057: return l;
058: }
059:
060: public void createControl(Composite parent) {
061: setControl(new Composite(parent, SWT.NONE));
062: parent.getDisplay().asyncExec(new Runnable() {
063: public void run() {
064: final IWizard wizard = getWizard();
065: if (wizard instanceof WorkflowWizard) {
066: try {
067: getContainer().run(true, true,
068: new IRunnableWithProgress() {
069:
070: public void run(
071: IProgressMonitor monitor)
072: throws InvocationTargetException,
073: InterruptedException {
074: ((WorkflowWizard) wizard)
075: .getWorkflow().next(
076: monitor);
077: }
078:
079: });
080: } catch (Exception e) {
081: MapGraphicPlugin.log("", e); //$NON-NLS-1$
082: }
083: } else {
084: getWizard().performFinish();
085: }
086: if (Display.getCurrent() == null) { //wizard is invisible
087: Display.getDefault().asyncExec(new Runnable() {
088: public void run() {
089: close();
090: }
091: });
092: }
093: }
094: });
095: }
096:
097: void close() {
098: if (getContainer() != null && getContainer().getShell() != null
099: && !getContainer().getShell().isDisposed()) {
100: getContainer().getShell().close();
101: }
102: }
103: }
|