Search in sources :

Example 1 with IDocumentProvider

use of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider in project tdi-studio-se by Talend.

the class SaveAsBusinessModelAction method run.

@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);
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IRepositoryNode(org.talend.repository.model.IRepositoryNode) BusinessDiagramEditor(org.talend.designer.business.model.business.diagram.part.BusinessDiagramEditor) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) IEditorPart(org.eclipse.ui.IEditorPart) IDocumentProvider(org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IDocumentProvider (org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 BusinessProcessItem (org.talend.core.model.properties.BusinessProcessItem)1 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)1 BusinessDiagramEditor (org.talend.designer.business.model.business.diagram.part.BusinessDiagramEditor)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1