1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.core.runtime.SafeRunner; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.jface.util.SafeRunnable; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.wizard.IWizard; 20 import org.eclipse.jface.wizard.IWizardNode; 21 import org.eclipse.swt.custom.BusyIndicator; 22 import org.eclipse.swt.graphics.Point; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.ui.IPluginContribution; 25 import org.eclipse.ui.IWorkbench; 26 import org.eclipse.ui.IWorkbenchWizard; 27 import org.eclipse.ui.internal.WorkbenchMessages; 28 import org.eclipse.ui.internal.WorkbenchPlugin; 29 import org.eclipse.ui.internal.util.Util; 30 import org.eclipse.ui.statushandlers.StatusAdapter; 31 import org.eclipse.ui.statushandlers.StatusManager; 32 import org.eclipse.ui.wizards.IWizardDescriptor; 33 34 44 public abstract class WorkbenchWizardNode implements IWizardNode, 45 IPluginContribution { 46 protected WorkbenchWizardSelectionPage parentWizardPage; 47 48 protected IWizard wizard; 49 50 protected IWizardDescriptor wizardElement; 51 52 60 public WorkbenchWizardNode(WorkbenchWizardSelectionPage aWizardPage, 61 IWizardDescriptor element) { 62 super(); 63 this.parentWizardPage = aWizardPage; 64 this.wizardElement = element; 65 } 66 67 74 public abstract IWorkbenchWizard createWizard() throws CoreException; 75 76 79 public void dispose() { 80 } 82 83 86 protected IStructuredSelection getCurrentResourceSelection() { 87 return parentWizardPage.getCurrentResourceSelection(); 88 } 89 90 93 public Point getExtent() { 94 return new Point(-1, -1); 95 } 96 97 100 public String getLocalId() { 101 IPluginContribution contribution = (IPluginContribution) Util.getAdapter(wizardElement, 102 IPluginContribution.class); 103 if (contribution != null) { 104 return contribution.getLocalId(); 105 } 106 return wizardElement.getId(); 107 } 108 109 112 public String getPluginId() { 113 IPluginContribution contribution = (IPluginContribution) Util.getAdapter(wizardElement, 114 IPluginContribution.class); 115 if (contribution != null) { 116 return contribution.getPluginId(); 117 } 118 return null; 119 } 120 121 124 public IWizard getWizard() { 125 if (wizard != null) { 126 return wizard; } 128 129 final IWorkbenchWizard[] workbenchWizard = new IWorkbenchWizard[1]; 130 final IStatus statuses[] = new IStatus[1]; 131 BusyIndicator.showWhile(parentWizardPage.getShell().getDisplay(), 133 new Runnable () { 134 public void run() { 135 SafeRunner.run(new SafeRunnable() { 136 139 public void handleException(Throwable e) { 140 IPluginContribution contribution = (IPluginContribution) Util.getAdapter(wizardElement, IPluginContribution.class); 141 statuses[0] = new Status( 142 IStatus.ERROR, 143 contribution != null ? contribution.getPluginId() : WorkbenchPlugin.PI_WORKBENCH, 144 IStatus.OK, 145 WorkbenchMessages.WorkbenchWizard_errorMessage, 146 e); 147 } 148 149 public void run() { 150 try { 151 workbenchWizard[0] = createWizard(); 152 } catch (CoreException e) { 154 IPluginContribution contribution = (IPluginContribution) Util.getAdapter(wizardElement, IPluginContribution.class); 155 statuses[0] = new Status( 156 IStatus.ERROR, 157 contribution != null ? contribution.getPluginId() : WorkbenchPlugin.PI_WORKBENCH, 158 IStatus.OK, 159 WorkbenchMessages.WorkbenchWizard_errorMessage, 160 e); 161 } 162 } 163 }); 164 } 165 }); 166 167 if (statuses[0] != null) { 168 parentWizardPage 169 .setErrorMessage(WorkbenchMessages.WorkbenchWizard_errorMessage); 170 StatusAdapter statusAdapter = new StatusAdapter(statuses[0]); 171 statusAdapter.addAdapter(Shell.class, parentWizardPage.getShell()); 172 statusAdapter.setProperty(StatusAdapter.TITLE_PROPERTY, 173 WorkbenchMessages.WorkbenchWizard_errorTitle); 174 StatusManager.getManager() 175 .handle(statusAdapter, StatusManager.SHOW); 176 return null; 177 } 178 179 IStructuredSelection currentSelection = getCurrentResourceSelection(); 180 181 currentSelection = wizardElement.adaptedSelection(currentSelection); 184 185 workbenchWizard[0].init(getWorkbench(), currentSelection); 186 187 wizard = workbenchWizard[0]; 188 return wizard; 189 } 190 191 196 public IWizardDescriptor getWizardElement() { 197 return wizardElement; 198 } 199 200 203 protected IWorkbench getWorkbench() { 204 return parentWizardPage.getWorkbench(); 205 } 206 207 210 public boolean isContentCreated() { 211 return wizard != null; 212 } 213 } 214 | Popular Tags |