Search in sources :

Example 96 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project InformationSystem by ObeoNetwork.

the class OverviewModelWizard method performFinish.

/**
 * Do the work after everything is specified.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@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.
                    // 
                    Root rootObject = createInitialModel();
                    if (rootObject != null) {
                        resource.getContents().add(rootObject);
                        overviewModelDef.initModel(rootObject);
                    }
                    // Save the contents of the resource to the file system.
                    // 
                    Map<Object, Object> options = new HashMap<Object, Object>();
                    options.put(XMLResource.OPTION_ENCODING, "UTF-8");
                    resource.save(options);
                } catch (Exception exception) {
                    OverviewEditorPlugin.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);
                }
            });
        }
        // Open an editor on the new file.
        overviewModelDef.openEditor(modelFile);
        return true;
    } catch (Exception exception) {
        OverviewEditorPlugin.INSTANCE.log(exception);
        return true;
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Root(org.obeonetwork.dsl.overview.Root) 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) MissingResourceException(java.util.MissingResourceException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISetSelectionTarget(org.eclipse.ui.part.ISetSelectionTarget)

Example 97 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project gemoc-studio by eclipse.

the class FsmModelWizard 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) {
                    FsmEditorPlugin.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(), FsmEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());
            return false;
        }
        return true;
    } catch (Exception exception) {
        FsmEditorPlugin.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 98 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project webtools.servertools by eclipse.

the class ShowInDebugAction method selectProcess.

protected void selectProcess(IProcess process) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            IWorkbenchPart part = page.findView(IDebugUIConstants.ID_DEBUG_VIEW);
            if (part == null) {
                try {
                    part = page.showView(IDebugUIConstants.ID_DEBUG_VIEW);
                } catch (PartInitException e) {
                    if (Trace.SEVERE) {
                        Trace.trace(Trace.STRING_SEVERE, "Could not open debug view");
                    }
                }
            }
            if (part != null) {
                IDebugView view = (IDebugView) part.getAdapter(IDebugView.class);
                if (view != null) {
                    page.activate(part);
                    view.setFocus();
                    Viewer viewer = view.getViewer();
                    if (viewer != null) {
                        viewer.setSelection(new StructuredSelection(process));
                    }
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Viewer(org.eclipse.jface.viewers.Viewer) PartInitException(org.eclipse.ui.PartInitException) IDebugView(org.eclipse.debug.ui.IDebugView)

Example 99 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project jbosstools-openshift by jbosstools.

the class CDKActionProvider method bringViewToFront.

private static final IWorkbenchPart bringViewToFront(String viewId) throws PartInitException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPart part = null;
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {
            part = page.findView(viewId);
            if (part == null) {
                part = page.showView(viewId);
            } else {
                page.activate(part);
                part.setFocus();
            }
        }
    }
    return part;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 100 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project jbosstools-openshift by jbosstools.

the class UIUtils method getCurrentSelection.

/**
 * Use this method instead of HandlerUtil.getCurrentSelection(event)
 * when action is called on Properties View.
 *
 * @param event
 * @return
 */
public static ISelection getCurrentSelection(ExecutionEvent event) {
    IWorkbenchPart part = HandlerUtil.getActivePart(event);
    IWorkbenchPartSite site = (part != null) ? part.getSite() : null;
    IWorkbenchWindow window = (site != null) ? site.getWorkbenchWindow() : null;
    ISelectionService service = (window != null) ? window.getSelectionService() : null;
    return service != null ? service.getSelection() : null;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelectionService(org.eclipse.ui.ISelectionService)

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