Search in sources :

Example 81 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project metalib by softlang.

the class FsmlModelWizard method performFinish.

/**
 * Do the work after everything is specified.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public boolean performFinish() {
    try {
        // Remember the file.
        // 
        final IFile modelFile = getModelFile();
        // Do the work within an operation.
        // 
        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor progressMonitor) {
                try {
                    // Create a resource set
                    // 
                    ResourceSet resourceSet = new ResourceSetImpl();
                    // Get the URI of the model file.
                    // 
                    URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
                    // Create a resource for this file.
                    // 
                    Resource resource = resourceSet.createResource(fileURI);
                    // Add the initial model object to the contents.
                    // 
                    EObject rootObject = createInitialModel();
                    if (rootObject != null) {
                        resource.getContents().add(rootObject);
                    }
                    // Save the contents of the resource to the file system.
                    // 
                    Map<Object, Object> options = new HashMap<Object, Object>();
                    options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
                    resource.save(options);
                } catch (Exception exception) {
                    FsmlEditorPlugin.INSTANCE.log(exception);
                } finally {
                    progressMonitor.done();
                }
            }
        };
        getContainer().run(false, false, operation);
        // Select the new file resource in the current view.
        // 
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(modelFile);
            getShell().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }
        // 
        try {
            page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
        } catch (PartInitException exception) {
            MessageDialog.openError(workbenchWindow.getShell(), FsmlEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
            return false;
        }
        return true;
    } catch (Exception exception) {
        FsmlEditorPlugin.INSTANCE.log(exception);
        return false;
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) IResource(org.eclipse.core.resources.IResource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) PartInitException(org.eclipse.ui.PartInitException) MissingResourceException(java.util.MissingResourceException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) EObject(org.eclipse.emf.ecore.EObject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) EObject(org.eclipse.emf.ecore.EObject) PartInitException(org.eclipse.ui.PartInitException)

Example 82 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project metalib by softlang.

the class FsmlModelWizard method performFinish.

/**
 * Do the work after everything is specified.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public boolean performFinish() {
    try {
        // Remember the file.
        // 
        final IFile modelFile = getModelFile();
        // Do the work within an operation.
        // 
        WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor progressMonitor) {
                try {
                    // Create a resource set
                    // 
                    ResourceSet resourceSet = new ResourceSetImpl();
                    // Get the URI of the model file.
                    // 
                    URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true);
                    // Create a resource for this file.
                    // 
                    Resource resource = resourceSet.createResource(fileURI);
                    // Add the initial model object to the contents.
                    // 
                    EObject rootObject = createInitialModel();
                    if (rootObject != null) {
                        resource.getContents().add(rootObject);
                    }
                    // Save the contents of the resource to the file system.
                    // 
                    Map<Object, Object> options = new HashMap<Object, Object>();
                    options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding());
                    resource.save(options);
                } catch (Exception exception) {
                    FsmlEditorPlugin.INSTANCE.log(exception);
                } finally {
                    progressMonitor.done();
                }
            }
        };
        getContainer().run(false, false, operation);
        // Select the new file resource in the current view.
        // 
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        IWorkbenchPage page = workbenchWindow.getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(modelFile);
            getShell().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }
        // 
        try {
            page.openEditor(new FileEditorInput(modelFile), workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId());
        } catch (PartInitException exception) {
            MessageDialog.openError(workbenchWindow.getShell(), FsmlEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
            return false;
        }
        return true;
    } catch (Exception exception) {
        FsmlEditorPlugin.INSTANCE.log(exception);
        return false;
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) HashMap(java.util.HashMap) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) IResource(org.eclipse.core.resources.IResource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) PartInitException(org.eclipse.ui.PartInitException) MissingResourceException(java.util.MissingResourceException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) EObject(org.eclipse.emf.ecore.EObject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) EObject(org.eclipse.emf.ecore.EObject) PartInitException(org.eclipse.ui.PartInitException)

Example 83 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project tdq-studio-se by Talend.

the class RepositoryNodeHelper method getRootNode.

/**
 * DOC klliu Comment method "getRootNode".
 *
 * @return
 */
public static RepositoryNode getRootNode(ERepositoryObjectType nodeName) {
    // MOD klliu bug 19138 In DI that can't find MDMConnectionFolderRepNode when create MDM connection
    // ~2011-03-22
    // FIXME: why we need this check?? we have the same two returns.
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow != null) {
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        IWorkbenchPart activePart = activePage == null ? null : activePage.getActivePart();
        if (activePart != null && activePart.getTitle().equals(DI_REPOSITORY_NAME)) {
            return getRootNode(nodeName, true);
        }
    }
    // ~
    return getRootNode(nodeName, true);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 84 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project tdq-studio-se by Talend.

the class LocalRepositoryObjectCRUD method getUISelection.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.views.resources.IRepositoryObjectCRUD#getUISelection()
     */
@Override
public ISelection getUISelection() {
    ISelection sel = null;
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (activeWorkbenchWindow != null) {
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        if (activePage != null) {
            IWorkbenchPart activePart = activePage.getActivePart();
            if (activePart != null) {
                if (activePart instanceof DQRespositoryView) {
                    sel = ((DQRespositoryView) activePart).getCommonViewer().getSelection();
                }
            }
        }
    }
    return sel;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView)

Example 85 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project whole by wholeplatform.

the class WholePluginProjectWizard method performFinish.

public boolean performFinish() {
    // outside WorkspaceModifyOperation.execute() due to a concurrency bug of OSGI
    final IBindingManager params = BindingManagerFactory.instance.createArguments();
    params.wDefValue("projectName", newProjectCreationPage.getProjectName());
    params.wDefValue("pluginId", newProjectCreationPage.getPluginId());
    params.wDefValue("pluginVersion", newProjectCreationPage.getPluginVersion());
    params.wDefValue("pluginName", newProjectCreationPage.getPluginName());
    params.wDefValue("pluginProvider", newProjectCreationPage.getPluginProvider());
    if (!newProjectCreationPage.useDefaults())
        params.wDefValue("locationURI", newProjectCreationPage.getLocationURI());
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        protected void execute(IProgressMonitor progressMonitor) {
            try {
                progressMonitor.beginTask("Generating...", IOperationProgressMonitor.TOTAL_WORK);
                params.wDefValue("progressMonitor", new OperationProgressMonitorAdapter(progressMonitor));
                IEntity projectTemplate = ProjectsArtifactsTemplateManager.instance().create("WholePluginProject");
                projectTemplate = BehaviorUtils.evaluate(projectTemplate, 1, params);
                Matcher.removeVars(projectTemplate, false);
                ArtifactsGeneratorOperation.generate(projectTemplate, params);
            } catch (Exception exception) {
                E4CompatibilityPlugin.log(exception);
            } finally {
                progressMonitor.done();
            }
        }
    };
    try {
        getContainer().run(false, false, operation);
    } catch (Exception exception) {
        E4CompatibilityPlugin.log(exception);
        return false;
    }
    if (project != null) {
        IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
        final IWorkbenchPart activePart = page.getActivePart();
        if (activePart instanceof ISetSelectionTarget) {
            final ISelection targetSelection = new StructuredSelection(project);
            getShell().getDisplay().asyncExec(new Runnable() {

                public void run() {
                    ((ISetSelectionTarget) activePart).selectReveal(targetSelection);
                }
            });
        }
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEntity(org.whole.lang.model.IEntity) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) IBindingManager(org.whole.lang.bindings.IBindingManager) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget) OperationProgressMonitorAdapter(org.whole.lang.operations.OperationProgressMonitorAdapter)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)289 ISelection (org.eclipse.jface.viewers.ISelection)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)112 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)72 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)69 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)59 IEditorPart (org.eclipse.ui.IEditorPart)57 IFile (org.eclipse.core.resources.IFile)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)44 IResource (org.eclipse.core.resources.IResource)42 PartInitException (org.eclipse.ui.PartInitException)41 ArrayList (java.util.ArrayList)36 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)35 FileEditorInput (org.eclipse.ui.part.FileEditorInput)33 HashMap (java.util.HashMap)32 EObject (org.eclipse.emf.ecore.EObject)31 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)31 URI (org.eclipse.emf.common.util.URI)30 MissingResourceException (java.util.MissingResourceException)29 Resource (org.eclipse.emf.ecore.resource.Resource)29