/* | |
* | |
*/ | |
package comrel.diagram.part; | |
import java.lang.reflect.InvocationTargetException; | |
import org.eclipse.core.runtime.CoreException; | |
import org.eclipse.core.runtime.IProgressMonitor; | |
import org.eclipse.emf.ecore.resource.Resource; | |
import org.eclipse.jface.dialogs.ErrorDialog; | |
import org.eclipse.jface.operation.IRunnableWithProgress; | |
import org.eclipse.jface.viewers.IStructuredSelection; | |
import org.eclipse.jface.wizard.Wizard; | |
import org.eclipse.ui.INewWizard; | |
import org.eclipse.ui.IWorkbench; | |
import org.eclipse.ui.PartInitException; | |
import org.eclipse.ui.actions.WorkspaceModifyOperation; | |
/** | |
* @generated | |
*/ | |
public class ComrelCreationWizard extends Wizard implements INewWizard { | |
private ComrelCustomCreationWizardPage customPage; | |
/** | |
* @generated | |
*/ | |
private IWorkbench workbench; | |
/** | |
* @generated | |
*/ | |
protected IStructuredSelection selection; | |
/** | |
* @generated | |
*/ | |
protected ComrelCreationWizardPage diagramModelFilePage; | |
/** | |
* @generated | |
*/ | |
protected ComrelCreationWizardPage domainModelFilePage; | |
/** | |
* @generated | |
*/ | |
protected Resource diagram; | |
/** | |
* @generated | |
*/ | |
private boolean openNewlyCreatedDiagramEditor = true; | |
/** | |
* @generated | |
*/ | |
public IWorkbench getWorkbench() { | |
return workbench; | |
} | |
/** | |
* @generated | |
*/ | |
public IStructuredSelection getSelection() { | |
return selection; | |
} | |
/** | |
* @generated | |
*/ | |
public final Resource getDiagram() { | |
return diagram; | |
} | |
/** | |
* @generated | |
*/ | |
public final boolean isOpenNewlyCreatedDiagramEditor() { | |
return openNewlyCreatedDiagramEditor; | |
} | |
/** | |
* @generated | |
*/ | |
public void setOpenNewlyCreatedDiagramEditor( | |
boolean openNewlyCreatedDiagramEditor) { | |
this.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor; | |
} | |
/** | |
* @generated | |
*/ | |
public void init(IWorkbench workbench, IStructuredSelection selection) { | |
this.workbench = workbench; | |
this.selection = selection; | |
setWindowTitle(Messages.ComrelCreationWizardTitle); | |
setDefaultPageImageDescriptor(ComrelDiagramEditorPlugin | |
.getBundledImageDescriptor("icons/wizban/NewComrelWizard.gif")); //$NON-NLS-1$ | |
setNeedsProgressMonitor(true); | |
} | |
/** | |
* @generated NOT | |
*/ | |
public void addPages() { | |
diagramModelFilePage = new ComrelCreationWizardPage( | |
"DiagramModelFile", getSelection(), "comrel_diagram"); //$NON-NLS-1$ //$NON-NLS-2$ | |
diagramModelFilePage | |
.setTitle(Messages.ComrelCreationWizard_DiagramModelFilePageTitle); | |
diagramModelFilePage | |
.setDescription(Messages.ComrelCreationWizard_DiagramModelFilePageDescription); | |
addPage(diagramModelFilePage); | |
domainModelFilePage = new ComrelCreationWizardPage( | |
"DomainModelFile", getSelection(), "comrel") { //$NON-NLS-1$ //$NON-NLS-2$ | |
public void setVisible(boolean visible) { | |
if (visible) { | |
String fileName = diagramModelFilePage.getFileName(); | |
fileName = fileName.substring(0, fileName.length() | |
- ".comrel_diagram".length()); //$NON-NLS-1$ | |
setFileName(ComrelDiagramEditorUtil.getUniqueFileName( | |
getContainerFullPath(), fileName, "comrel")); //$NON-NLS-1$ | |
} | |
super.setVisible(visible); | |
} | |
}; | |
domainModelFilePage | |
.setTitle(Messages.ComrelCreationWizard_DomainModelFilePageTitle); | |
domainModelFilePage | |
.setDescription(Messages.ComrelCreationWizard_DomainModelFilePageDescription); | |
addPage(domainModelFilePage); | |
customPage = new ComrelCustomCreationWizardPage( | |
"Composite Refactoring Details"); | |
customPage.setTitle("Composite Refactoring Details"); | |
addPage(customPage); | |
} | |
/** | |
* @generated NOT | |
*/ | |
public boolean performFinish() { | |
IRunnableWithProgress op = new WorkspaceModifyOperation(null) { | |
protected void execute(IProgressMonitor monitor) | |
throws CoreException, InterruptedException { | |
diagram = ComrelDiagramEditorUtil.createDiagram( | |
diagramModelFilePage.getURI(), domainModelFilePage | |
.getURI(), monitor, customPage.getDiagramName() | |
.getText(), customPage.getNamespaceURI() | |
.getText(), customPage | |
.getConnectionVisualization().getText()); | |
if (isOpenNewlyCreatedDiagramEditor() && diagram != null) { | |
try { | |
ComrelDiagramEditorUtil.openDiagram(diagram); | |
} catch (PartInitException e) { | |
ErrorDialog.openError(getContainer().getShell(), | |
Messages.ComrelCreationWizardOpenEditorError, | |
null, e.getStatus()); | |
} | |
} | |
} | |
}; | |
try { | |
getContainer().run(false, true, op); | |
} catch (InterruptedException e) { | |
return false; | |
} catch (InvocationTargetException e) { | |
if (e.getTargetException() instanceof CoreException) { | |
ErrorDialog.openError(getContainer().getShell(), | |
Messages.ComrelCreationWizardCreationError, null, | |
((CoreException) e.getTargetException()).getStatus()); | |
} else { | |
ComrelDiagramEditorPlugin.getInstance().logError( | |
"Error creating diagram", e.getTargetException()); //$NON-NLS-1$ | |
} | |
return false; | |
} | |
return diagram != null; | |
} | |
} |