コード例 #1
0
 /** @generated */
 protected void performSaveAs(IProgressMonitor progressMonitor) {
   Shell shell = getSite().getShell();
   IEditorInput input = getEditorInput();
   SaveAsDialog dialog = new SaveAsDialog(shell);
   IFile original =
       input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null;
   if (original != null) {
     dialog.setOriginalFile(original);
   }
   dialog.create();
   IDocumentProvider provider = getDocumentProvider();
   if (provider == null) {
     // editor has been programmatically closed while the dialog was open
     return;
   }
   if (provider.isDeleted(input) && original != null) {
     String message =
         NLS.bind(Messages.SqlmodelDiagramEditor_SavingDeletedFile, original.getName());
     dialog.setErrorMessage(null);
     dialog.setMessage(message, IMessageProvider.WARNING);
   }
   if (dialog.open() == Window.CANCEL) {
     if (progressMonitor != null) {
       progressMonitor.setCanceled(true);
     }
     return;
   }
   IPath filePath = dialog.getResult();
   if (filePath == null) {
     if (progressMonitor != null) {
       progressMonitor.setCanceled(true);
     }
     return;
   }
   IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
   IFile file = workspaceRoot.getFile(filePath);
   final IEditorInput newInput = new FileEditorInput(file);
   // Check if the editor is already open
   IEditorMatchingStrategy matchingStrategy = getEditorDescriptor().getEditorMatchingStrategy();
   IEditorReference[] editorRefs =
       PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
   for (int i = 0; i < editorRefs.length; i++) {
     if (matchingStrategy.matches(editorRefs[i], newInput)) {
       MessageDialog.openWarning(
           shell,
           Messages.SqlmodelDiagramEditor_SaveAsErrorTitle,
           Messages.SqlmodelDiagramEditor_SaveAsErrorMessage);
       return;
     }
   }
   boolean success = false;
   try {
     provider.aboutToChange(newInput);
     getDocumentProvider(newInput)
         .saveDocument(
             progressMonitor, newInput, getDocumentProvider().getDocument(getEditorInput()), true);
     success = true;
   } catch (CoreException x) {
     IStatus status = x.getStatus();
     if (status == null || status.getSeverity() != IStatus.CANCEL) {
       ErrorDialog.openError(
           shell,
           Messages.SqlmodelDiagramEditor_SaveErrorTitle,
           Messages.SqlmodelDiagramEditor_SaveErrorMessage,
           x.getStatus());
     }
   } finally {
     provider.changed(newInput);
     if (success) {
       setInput(newInput);
     }
   }
   if (progressMonitor != null) {
     progressMonitor.setCanceled(!success);
   }
 }
コード例 #2
0
  @Override
  public void run() {
    SaveAsBusinessModelWizard businessModelWizard = new SaveAsBusinessModelWizard(editorPart);

    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), businessModelWizard);
    if (dlg.open() == Window.OK) {

      try {

        BusinessProcessItem businessProcessItem = businessModelWizard.getBusinessProcessItem();

        IRepositoryNode repositoryNode =
            RepositoryNodeUtilities.getRepositoryNode(
                businessProcessItem.getProperty().getId(), false);

        // because step1, the fresh will unload the resource(EMF), so, assign a new one...
        businessProcessItem =
            (BusinessProcessItem) repositoryNode.getObject().getProperty().getItem();

        IWorkbenchPage page = getActivePage();

        DiagramResourceManager diagramResourceManager =
            new DiagramResourceManager(page, new NullProgressMonitor());
        IFile file = businessModelWizard.getTempFile();
        // Set readonly to false since created job will always be editable.
        RepositoryEditorInput newBusinessModelEditorInput =
            new RepositoryEditorInput(file, businessProcessItem);

        newBusinessModelEditorInput.setRepositoryNode(repositoryNode);

        // here really do the normal save as function
        IDocumentProvider provider =
            ((BusinessDiagramEditor) this.editorPart).getDocumentProvider();

        provider.aboutToChange(newBusinessModelEditorInput);
        provider.saveDocument(
            null,
            newBusinessModelEditorInput,
            provider.getDocument(this.editorPart.getEditorInput()),
            true);
        provider.changed(newBusinessModelEditorInput);

        // copy back from the *.business_diagram file to *.item file.
        // @see:BusinessDiagramEditor.doSave(IProgressMonitor progressMonitor)
        diagramResourceManager.updateFromResource(
            businessProcessItem, newBusinessModelEditorInput.getFile());

        // notice: here, must save it, save the item to disk, otherwise close the editor
        // without any modification, there won't save the
        // model again, so, will lost the graphic when reopen it.
        ProxyRepositoryFactory.getInstance().save(businessProcessItem);

        // close the old editor
        page.closeEditor(this.editorPart, false);

        // open the new editor, because at the same time, there will update the
        // jobSetting/componentSetting view
        IEditorPart openEditor =
            page.openEditor(newBusinessModelEditorInput, BusinessDiagramEditor.ID, true);

      } catch (Exception e) {
        MessageDialog.openError(
            Display.getCurrent().getActiveShell(),
            "Error",
            "Business model could not be saved" + " : " + e.getMessage());
        ExceptionHandler.process(e);
      }
    }
  }