Search in sources :

Example 41 with IWorkbench

use of org.eclipse.ui.IWorkbench in project Palladio-Editors-Sirius by PalladioSimulator.

the class NewPalladioProjectWizard method openPalladioPerspective.

private void openPalladioPerspective() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    try {
        workbench.showPerspective(PERSPECTIVE_ID, window);
    } catch (WorkbenchException e) {
        MessageDialog.openError(getShell(), "Error", "Could not open Palladio Perspective");
        e.printStackTrace();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkbenchException(org.eclipse.ui.WorkbenchException)

Example 42 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class SpecfileElementHyperlinkDetector method prepareHyperlink.

private IHyperlink[] prepareHyperlink(IRegion lineInfo, String line, String word, SpecfileElement source, int lineIndex) {
    IRegion urlRegion = new Region(lineInfo.getOffset() + line.indexOf(word, lineIndex), word.length());
    // will only work with 1 active page
    // does not work with CompareEditor
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win.getActivePage();
    IEditorPart editor = page.getActiveEditor();
    // we can only provide this functionality for resources inside the workbench.
    if (editor.getEditorInput() instanceof FileEditorInput) {
        IFile original = ((FileEditorInput) editor.getEditorInput()).getFile();
        return new IHyperlink[] { new SpecfileElementHyperlink(urlRegion, source, original) };
    } else {
        return null;
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IRegion(org.eclipse.jface.text.IRegion)

Example 43 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class CreaterepoCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // $NON-NLS-1$
    final String executionType = event.getParameter("executionType");
    try {
        IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchPage wbPage = wb.getActiveWorkbenchWindow().getActivePage();
        IEditorInput editorInput = wbPage.getActiveEditor().getEditorInput();
        IResource resource = ResourceUtil.getResource(editorInput);
        final CreaterepoProject project = new CreaterepoProject(resource.getProject());
        Job executeCreaterepo = new Job(Messages.Createrepo_jobName) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    monitor.beginTask(Messages.CreaterepoProject_executeCreaterepo, IProgressMonitor.UNKNOWN);
                    MessageConsoleStream os = CreaterepoUtils.findConsole(Messages.CreaterepoProject_consoleName).newMessageStream();
                    if (executionType.equals("refresh")) {
                        // $NON-NLS-1$
                        return project.update(os);
                    } else {
                        return project.createrepo(os);
                    }
                } catch (CoreException e) {
                    Activator.logError(Messages.Createrepo_errorExecuting, e);
                } finally {
                    monitor.done();
                }
                return null;
            }
        };
        executeCreaterepo.setUser(true);
        executeCreaterepo.schedule();
    } catch (CoreException e) {
        Activator.logError(Messages.CreaterepoProject_executeCreaterepo, e);
    }
    return null;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) Job(org.eclipse.core.runtime.jobs.Job) CreaterepoProject(org.eclipse.linuxtools.internal.rpm.createrepo.CreaterepoProject) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Example 44 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class CreaterepoResourceChangeListener method closeEditors.

/**
 * Close the editors thats resource has been affected by a change in the
 * workspace. E.g. if an editor's project has been closed/deleted, close the
 * editor.
 */
private void closeEditors() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IResource repomdFile = project.getRepoFile();
    // deleted, or the file was deleted. If so, close the editor of the file.
    if (!repomdFile.exists()) {
        for (IWorkbenchPage page : workbench.getActiveWorkbenchWindow().getPages()) {
            for (IEditorReference ref : page.getEditorReferences()) {
                try {
                    // get the resource from the editor part and exit the editor if
                    // it is within the project(s) being closed/deleted
                    IResource resource = ResourceUtil.getResource(ref.getEditorInput());
                    if (ref.getId().equals(RepoFormEditor.EDITOR_ID) && resource.getProject().equals(project.getProject())) {
                        page.closeEditor(ref.getEditor(false), false);
                    }
                } catch (PartInitException e) {
                    Activator.logError(Messages.CreaterepoResourceChangeListener_errorGettingResource, e);
                }
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IResource(org.eclipse.core.resources.IResource)

Example 45 with IWorkbench

use of org.eclipse.ui.IWorkbench in project linuxtools by eclipse.

the class ChangeLogAction method createChangeLog.

protected IFile createChangeLog(IPath changelog) {
    IWorkspaceRoot myWorkspaceRoot = getWorkspaceRoot();
    IWorkbench ws = PlatformUI.getWorkbench();
    final IFile changelog_File = myWorkspaceRoot.getFile(changelog);
    final InputStream initialContents = new ByteArrayInputStream(new byte[0]);
    WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {

        @Override
        public void execute(IProgressMonitor monitor) throws CoreException {
            try {
                // $NON-NLS-1$
                monitor.beginTask(Messages.getString("ChangeLog.AddingChangeLog"), 2000);
                changelog_File.create(initialContents, false, monitor);
                if (monitor.isCanceled()) {
                    throw new OperationCanceledException();
                }
            } finally {
                monitor.done();
            }
        }
    };
    try {
        new ProgressMonitorDialog(ws.getActiveWorkbenchWindow().getShell()).run(true, true, operation);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInterrupted"), e);
        return null;
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrInvocation"), e);
        return null;
    }
    // FIXME:  we should put this refreshLocal call into a thread (filed as bug #256180)
    try {
        IContainer changelogContainer = myWorkspaceRoot.getContainerForLocation(changelog);
        if (changelogContainer != null)
            changelogContainer.refreshLocal(2, null);
    } catch (CoreException e) {
        // $NON-NLS-1$
        reportErr(Messages.getString("ChangeLog.ErrRefresh"), e);
        return null;
    }
    return changelog_File;
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IWorkbench(org.eclipse.ui.IWorkbench) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IContainer(org.eclipse.core.resources.IContainer)

Aggregations

IWorkbench (org.eclipse.ui.IWorkbench)105 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)32 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)31 IEditorPart (org.eclipse.ui.IEditorPart)21 PartInitException (org.eclipse.ui.PartInitException)20 WizardDialog (org.eclipse.jface.wizard.WizardDialog)15 CoreException (org.eclipse.core.runtime.CoreException)12 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)12 Shell (org.eclipse.swt.widgets.Shell)11 IResource (org.eclipse.core.resources.IResource)9 ISelection (org.eclipse.jface.viewers.ISelection)9 Display (org.eclipse.swt.widgets.Display)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)7 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)7 IProject (org.eclipse.core.resources.IProject)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 TableEditorInput (com.cubrid.common.ui.cubrid.table.editor.TableEditorInput)5 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)5