コード例 #1
0
  @Override
  protected IProgressMonitor executeCommand(final RefactorCommand command) {
    IProgressMonitor monitor = super.executeCommand(command);

    try {
      // Save refactored resource
      final ModelEditor editor = ModelerCore.getModelEditor();

      // defect 16527 - check that a resource is a file before casting
      IResource res = this.dest.findMember(MoveRefactorAction.this.resSelectedResource.getName());
      if (res instanceof IFile) {
        final IFile file = (IFile) res;
        ModelResource model = editor.findModelResource(file);
        if (model != null) {
          if (model.getEmfResource().isModified()) {
            // If an editor is open, call doSave on it, else tell the model to save
            org.teiid.designer.ui.editors.ModelEditor openEditor =
                ModelEditorManager.getModelEditorForFile(file, false);
            if (openEditor != null) {
              openEditor.doSave(monitor);
            } else {
              model.save(monitor, true);
            }
          }
        }
      } // endif -- move was on a file

      // Save modified dependent resources
      for (final Iterator iter = ((ResourceMoveCommand) command).getDependentResources().iterator();
          iter.hasNext(); ) {
        IFile file = (IFile) iter.next();
        ModelResource model = editor.findModelResource(file);
        if (model != null) {
          if (model.getEmfResource().isModified() && !model.isReadOnly()) {
            // If an editor is open, call doSave on it, else tell the model to save
            org.teiid.designer.ui.editors.ModelEditor openEditor =
                ModelEditorManager.getModelEditorForFile(file, false);
            if (openEditor != null) {
              openEditor.doSave(monitor);
            } else {
              model.save(monitor, true);
            }
          }
        }
      }
    } catch (final ModelWorkspaceException err) {
      ModelerCore.Util.log(err);
    }

    return monitor;
  }
コード例 #2
0
  /**
   * Should only be called if current object and model are not <code>null</code>.
   *
   * @since 5.5.3
   */
  private boolean openEditorIfNeeded(ModelResource currentModel) {
    boolean openEditorCancelled = false;
    // we only need to worry about the readonly status if the file is not currently open,
    // and its underlying IResource is not read only

    if (currentModel == null) {

    } else if (!isEditorOpen(currentModel)
        && !currentModel.getResource().getResourceAttributes().isReadOnly()) {
      final IFile modelFile = (IFile) currentModel.getResource();
      Shell shell = UiPlugin.getDefault().getCurrentWorkbenchWindow().getShell();

      // may want to change these text strings eventually:
      if (MessageDialog.openQuestion(
          shell, ModelEditorManager.OPEN_EDITOR_TITLE, ModelEditorManager.OPEN_EDITOR_MESSAGE)) {
        // load and activate, not async (to prevent multiple dialogs from coming up):
        // Changed to use method that insures Object editor mode is on
        ModelEditorManager.openInEditMode(
            modelFile, true, UiConstants.ObjectEditor.IGNORE_OPEN_EDITOR);

      } else {
        openEditorCancelled = true;
      }
    }

    return openEditorCancelled;
  }
コード例 #3
0
  private boolean isEditorOpen(ModelResource currentModel) {
    if (currentModel != null) {
      IFile modelFile = (IFile) currentModel.getResource();
      return (ModelEditorManager.isOpen(modelFile));
    }

    return false;
  }
コード例 #4
0
 /**
  * This method is called in the run() method of AbstractAction to give the actions a hook into
  * canceling the run at the last minute. This overrides the AbstractAction preRun() method.
  */
 @Override
 protected boolean preRun() {
   if (requiresEditorForRun() && sibling != null) {
     ModelResource mr = ModelUtilities.getModelResourceForModelObject(sibling);
     if (mr != null) {
       ModelEditorManager.activate(mr, true, true);
     }
   }
   return true;
 }
コード例 #5
0
  private EObject createViewProcedureInTxn(
      ModelResource modelResource, RelationalViewProcedure viewProcedure) {
    EObject newTable = null;

    boolean requiredStart =
        ModelerCore.startTxn(true, true, Messages.createRelationalViewProcedureTitle, this);
    boolean succeeded = false;
    try {
      ModelEditor editor =
          ModelEditorManager.getModelEditorForFile(
              (IFile) modelResource.getCorrespondingResource(), true);
      if (editor != null) {
        boolean isDirty = editor.isDirty();

        RelationalViewModelFactory factory = new RelationalViewModelFactory();

        RelationalModel relModel = new RelationalModel("dummy"); // $NON-NLS-1$
        relModel.addChild(viewProcedure);

        factory.build(modelResource, relModel, new NullProgressMonitor());

        if (!isDirty && editor.isDirty()) {
          editor.doSave(new NullProgressMonitor());
        }
        succeeded = true;

        for (Object child : modelResource.getEObjects()) {
          EObject eObj = (EObject) child;
          if (ModelerCore.getModelEditor()
              .getName(eObj)
              .equalsIgnoreCase(this.relationalViewProcedure.getName())) {
            newTable = eObj;
            break;
          }
        }
      }
    } catch (Exception e) {
      MessageDialog.openError(
          Display.getCurrent().getActiveShell(),
          Messages.createRelationalViewProcedureExceptionMessage,
          e.getMessage());
      IStatus status =
          new Status(
              IStatus.ERROR,
              UiConstants.PLUGIN_ID,
              Messages.createRelationalViewProcedureExceptionMessage,
              e);
      UiConstants.Util.log(status);

      return null;
    } finally {
      // if we started the txn, commit it.
      if (requiredStart) {
        if (succeeded) {
          ModelerCore.commitTxn();
        } else {
          ModelerCore.rollbackTxn();
        }
      }
    }

    return newTable;
  }