Search in sources :

Example 46 with IWorkbenchPart

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

the class ShowAllContainersCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final boolean checked = !HandlerUtil.toggleCommandState(event.getCommand());
    if (activePart instanceof DockerContainersView) {
        final DockerContainersView containersView = (DockerContainersView) activePart;
        containersView.showAllContainers(checked);
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DockerContainersView(org.eclipse.linuxtools.internal.docker.ui.views.DockerContainersView)

Example 47 with IWorkbenchPart

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

the class ShowInSystemExplorerCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<DockerContainerVolume> volumes = CommandUtils.getSelectedVolumes(activePart);
    if (volumes == null || volumes.isEmpty()) {
        return null;
    }
    final DockerContainerVolume selectedVolume = volumes.get(0);
    final File hostFile = new File(selectedVolume.getHostPath());
    final String launchCmd = getShowInSystemExplorerCommand(hostFile);
    if (launchCmd == null) {
        return null;
    }
    final Job job = new Job(CommandMessages.getString("command.showIn.systemExplorer")) {

        // $NON-NLS-1$
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final Process p = getLaunchProcess(launchCmd, hostFile);
                final int retCode = p.waitFor();
                if (retCode != 0 && !Util.isWindows()) {
                    Activator.log(new DockerException(CommandMessages.getFormattedString(// $NON-NLS-1$
                    "command.showIn.systemExplorer.failure.command.execute", launchCmd, Integer.toString(retCode))));
                }
            } catch (IOException | InterruptedException e) {
                Activator.logErrorMessage(CommandMessages.getFormattedString(// $NON-NLS-1$
                "command.showIn.systemExplorer.failure", launchCmd), e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DockerContainerVolume(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 48 with IWorkbenchPart

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

the class ShowInWebBrowserCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerPortMapping> portMappings = getSelectedPortMappings(activePart);
    if (portMappings == null || portMappings.isEmpty()) {
        return null;
    }
    final Job job = new Job(// $NON-NLS-1$
    CommandMessages.getString("command.showIn.webBrowser")) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final IDockerConnection currentConnection = getCurrentConnection(activePart);
                final IDockerPortMapping selectedPort = portMappings.get(0);
                final URI connectionURI = new URI(currentConnection.getUri());
                if (// $NON-NLS-1$
                "tcp".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "unix".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "http".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "https".equalsIgnoreCase(connectionURI.getScheme())) {
                    final String host = // $NON-NLS-1$
                    "unix".equalsIgnoreCase(connectionURI.getScheme()) ? "127.0.0.1" : // $NON-NLS-1$
                    connectionURI.getHost();
                    final URL location = new // $NON-NLS-1$
                    URL(// $NON-NLS-1$
                    "http", // $NON-NLS-1$
                    host, selectedPort.getPublicPort(), // $NON-NLS-1$
                    "/");
                    openLocationInWebBrowser(location);
                }
            } catch (URISyntaxException | MalformedURLException e) {
                Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
                "command.showIn.webBrowser.failure"), e);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MalformedURLException(java.net.MalformedURLException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) URISyntaxException(java.net.URISyntaxException) IDockerPortMapping(org.eclipse.linuxtools.docker.core.IDockerPortMapping) Job(org.eclipse.core.runtime.jobs.Job) URI(java.net.URI) URL(java.net.URL)

Example 49 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project knime-core by knime.

the class AbstractRepositoryView method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(final IViewSite site) throws PartInitException {
    super.init(site);
    // Bug#5807 set the initial focus on the search field.
    site.getPage().addPartListener(new IPartListener() {

        @Override
        public void partOpened(final IWorkbenchPart part) {
        }

        @Override
        public void partDeactivated(final IWorkbenchPart part) {
        }

        @Override
        public void partClosed(final IWorkbenchPart part) {
        }

        @Override
        public void partBroughtToTop(final IWorkbenchPart part) {
        }

        @Override
        public void partActivated(final IWorkbenchPart part) {
            if (part == AbstractRepositoryView.this) {
                m_toolbarSearchText.getText().setFocus();
            }
        }
    });
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IPartListener(org.eclipse.ui.IPartListener)

Example 50 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project dbeaver by dbeaver.

the class CompileHandler method updateElement.

@Override
public void updateElement(UIElement element, Map parameters) {
    List<OracleSourceObject> objects = new ArrayList<>();
    IWorkbenchPartSite partSite = UIUtils.getWorkbenchPartSite(element.getServiceLocator());
    if (partSite != null) {
        final ISelectionProvider selectionProvider = partSite.getSelectionProvider();
        if (selectionProvider != null) {
            ISelection selection = selectionProvider.getSelection();
            if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
                for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                    final Object item = iter.next();
                    final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(item, OracleSourceObject.class);
                    if (sourceObject != null) {
                        objects.add(sourceObject);
                    }
                }
            }
        }
        if (objects.isEmpty()) {
            final IWorkbenchPart activePart = partSite.getPart();
            final OracleSourceObject sourceObject = RuntimeUtils.getObjectAdapter(activePart, OracleSourceObject.class);
            if (sourceObject != null) {
                objects.add(sourceObject);
            }
        }
    }
    if (!objects.isEmpty()) {
        if (objects.size() > 1) {
            element.setText("Compile " + objects.size() + " objects");
        } else {
            final OracleSourceObject sourceObject = objects.get(0);
            String objectType = TextUtils.formatWord(sourceObject.getSourceType().name());
            element.setText("Compile " + objectType);
        }
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OracleSourceObject(org.jkiss.dbeaver.ext.oracle.model.source.OracleSourceObject)

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