예제 #1
0
  /**
   * This method should be called within a workspace modify operation since it creates resources.
   *
   * @generated
   */
  public static Resource createDiagram(
      URI diagramURI, URI modelURI, IProgressMonitor progressMonitor) {
    TransactionalEditingDomain editingDomain =
        GMFEditingDomainFactory.INSTANCE.createEditingDomain();
    progressMonitor.beginTask(Messages.UMLDiagramEditorUtil_CreateDiagramProgressTask, 3);
    final Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
    final Resource modelResource = editingDomain.getResourceSet().createResource(modelURI);
    final String diagramName = diagramURI.lastSegment();
    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            editingDomain,
            Messages.UMLDiagramEditorUtil_CreateDiagramCommandLabel,
            Collections.EMPTY_LIST) {

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            Package model = createInitialModel();
            attachModelToResource(model, modelResource);

            Diagram diagram =
                ViewService.createDiagram(
                    model,
                    PackageEditPart.MODEL_ID,
                    UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            if (diagram != null) {
              diagramResource.getContents().add(diagram);
              diagram.setName(diagramName);
              diagram.setElement(model);
            }

            try {
              modelResource.save(
                  org.eclipse.papyrus.uml.diagram.statemachine.part.UMLDiagramEditorUtil
                      .getSaveOptions());
              diagramResource.save(
                  org.eclipse.papyrus.uml.diagram.statemachine.part.UMLDiagramEditorUtil
                      .getSaveOptions());
            } catch (IOException e) {

              UMLDiagramEditorPlugin.getInstance()
                  .logError("Unable to store model and diagram resources", e); // $NON-NLS-1$
            }
            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new SubProgressMonitor(progressMonitor, 1), null);
    } catch (ExecutionException e) {
      UMLDiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    }
    setCharset(WorkspaceSynchronizer.getFile(modelResource));
    setCharset(WorkspaceSynchronizer.getFile(diagramResource));
    return diagramResource;
  }
예제 #2
0
 /** @generated */
 public static void setCharset(IFile file) {
   if (file == null) {
     return;
   }
   try {
     file.setCharset("UTF-8", new NullProgressMonitor()); // $NON-NLS-1$
   } catch (CoreException e) {
     UMLDiagramEditorPlugin.getInstance()
         .logError("Unable to set charset for file " + file.getFullPath(), e); // $NON-NLS-1$
   }
 }
예제 #3
0
 /** @generated */
 public Object evaluate(Object context, Map env) {
   if (context().isInstance(context)) {
     try {
       return doEvaluate(context, env);
     } catch (Exception e) {
       UMLDiagramEditorPlugin.getInstance()
           .logError("Expression evaluation failure: " + body(), e); // $NON-NLS-1$
     }
   }
   return null;
 }
예제 #4
0
 /**
  * Runs the wizard in a dialog.
  *
  * @generated
  */
 public static void runWizard(Shell shell, Wizard wizard, String settingsKey) {
   IDialogSettings pluginDialogSettings = UMLDiagramEditorPlugin.getInstance().getDialogSettings();
   IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey);
   if (wizardDialogSettings == null) {
     wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey);
   }
   wizard.setDialogSettings(wizardDialogSettings);
   WizardDialog dialog = new WizardDialog(shell, wizard);
   dialog.create();
   dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
   dialog.open();
 }
예제 #5
0
 /** @generated */
 protected void setStatus(int severity, String message, Throwable throwable) {
   String pluginID = UMLDiagramEditorPlugin.ID;
   this.status =
       new Status(
           severity, pluginID, -1, (message != null) ? message : "", throwable); // $NON-NLS-1$
   if (!this.status.isOK()) {
     UMLDiagramEditorPlugin.getInstance()
         .logError(
             "Expression problem:" + message + "body:" + body(),
             throwable); //$NON-NLS-1$ //$NON-NLS-2$
   }
 }