Search in sources :

Example 56 with IWorkbenchPart

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

the class NavigatorHandlerObjectGoto method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    DBCExecutionContext context = null;
    DBSObject container = null;
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof DBPContextProvider) {
        context = ((DBPContextProvider) activePart).getExecutionContext();
    } else if (activePart instanceof INavigatorModelView) {
        final ISelection selection = HandlerUtil.getCurrentSelection(event);
        if (selection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof DBSWrapper) {
                DBSObject object = ((DBSWrapper) element).getObject();
                if (object != null) {
                    container = object;
                    while (container instanceof DBSFolder) {
                        container = container.getParentObject();
                    }
                    DBPDataSource dataSource = object.getDataSource();
                    if (dataSource != null) {
                        context = dataSource.getDefaultContext(true);
                    }
                }
            }
        }
    }
    if (context == null) {
        DBUserInterface.getInstance().showError("Go to object", "No active datasource");
        return null;
    }
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
    dialog.open();
    Object[] objectsToOpen = dialog.getResult();
    if (!ArrayUtils.isEmpty(objectsToOpen)) {
        Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
        for (DBNDatabaseNode node : nodes) {
            NavigatorUtils.openNavigatorNode(node, workbenchWindow);
        }
    }
    return null;
}
Also used : DBSFolder(org.jkiss.dbeaver.model.struct.DBSFolder) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBPContextProvider(org.jkiss.dbeaver.model.DBPContextProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) GotoObjectDialog(org.jkiss.dbeaver.ui.dialogs.GotoObjectDialog) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 57 with IWorkbenchPart

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

the class ImportCommandStackHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
    dialog.setFilterExtensions(new String[] { "*.xml" });
    String importFile = dialog.open();
    if (importFile == null) {
        // cancelled
        return null;
    }
    log.log(Level.INFO, "Importing command stack from file: " + importFile);
    // get command stack object
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    IWorkbenchPart part = window.getActivePage().findView(CommandStackView.ID);
    CommandStackView commandStackView = (CommandStackView) part;
    // import new commands
    for (StackedCommand sc : parseCommandStack(importFile)) {
        commandStackView.addTelecommand(sc);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 58 with IWorkbenchPart

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

the class AddManualEventHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    EventLogView view = (EventLogView) part;
    String action = event.getParameter(EVENT_ADD_ACTION);
    if (action.equals(EVENT_ADD)) {
        AddManualEventDialog addManualEventDialog = new AddManualEventDialog(part.getSite().getShell());
        int result = addManualEventDialog.open();
    } else {
        // action.equals(EVENT_INSERT)
        ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
        // get selected event and open a manual event dialog using the selected generation time.
        if (sel != null && sel instanceof IStructuredSelection) {
            IStructuredSelection selection = (IStructuredSelection) sel;
            Iterator<?> it = selection.iterator();
            Event rec = (Event) it.next();
            long generationTime = rec.getGenerationTime();
            AddManualEventDialog addManualEventDialog = new AddManualEventDialog(part.getSite().getShell(), generationTime);
            int result = addManualEventDialog.open();
        }
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.yamcs.protobuf.Yamcs.Event) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 59 with IWorkbenchPart

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

the class RefreshArchiveHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Disable refresh button, to prevent double-click from the user
    RefreshStateProvider provider = RCPUtils.findSourceProvider(event, RefreshStateProvider.STATE_KEY_ENABLED, RefreshStateProvider.class);
    provider.setEnabled(false);
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    // We trust on the ArchiveView to re-enable the commandState (on the swt-thread) once it's done
    SwingUtilities.invokeLater(() -> ((ArchiveView) part).refreshData());
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart)

Example 60 with IWorkbenchPart

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

the class ClearCommandHistoryHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
    CommandHistoryView view = (CommandHistoryView) part;
    view.clear();
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart)

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