Search in sources :

Example 1 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project flux by eclipse.

the class SyncDisconnectHandler method getSelectedProjects.

protected IProject[] getSelectedProjects(ISelection selection) {
    List<IProject> selectedProjects = new ArrayList<IProject>();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object[] selectedObjects = structuredSelection.toArray();
        for (int i = 0; i < selectedObjects.length; i++) {
            if (selectedObjects[i] instanceof IAdaptable) {
                IProject project = (IProject) ((IAdaptable) selectedObjects[i]).getAdapter(IProject.class);
                if (project != null) {
                    selectedProjects.add(project);
                }
            }
        }
    }
    return (IProject[]) selectedProjects.toArray(new IProject[selectedProjects.size()]);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 2 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project jop by jop-devel.

the class ToggleJOPNatureAction method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext(); ) {
            Object element = it.next();
            IProject project = null;
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }
            if (project != null) {
                toggleNature(project);
                System.err.println(project + " > Nature");
                PropertyTester jopPropTest = new JOPNaturePropertyTester();
                jopPropTest.test(project, "hasJOPNature", null, null);
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) PropertyTester(org.eclipse.core.expressions.PropertyTester) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject)

Example 3 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project gfm_viewer by satyagraha.

the class GenerateMarkdownPreview method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    LOGGER.fine("");
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    for (@SuppressWarnings("rawtypes") Iterator items = selection.iterator(); items.hasNext(); ) {
        Object item = items.next();
        if (item instanceof IFile) {
            scheduler.generateIFile((IFile) item);
        } else if (item instanceof IFolder) {
            scheduler.generateIFolder((IFolder) item);
        } else {
            LOGGER.fine("unexpected selection: " + item);
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project gfm_viewer by satyagraha.

the class ShowMarkdownFile method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    LOGGER.fine("");
    IStructuredSelection structuredSelection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    Object firstElement = structuredSelection.getFirstElement();
    if (firstElement instanceof IFile) {
        ViewManager.activateView(event, MarkdownView.ID);
        IFile iFile = (IFile) firstElement;
        try {
            DIManager.getDefault().getInjector(Scope.PAGE).getInstance(ViewerActions.class).showMarkdownFile(iFile);
        } catch (IOException e) {
            throw new ExecutionException("could not show file", e);
        }
    } else {
        LOGGER.fine("unexpected selection: " + firstElement);
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) ViewerActions(code.satyagraha.gfm.viewer.model.api.ViewerActions) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 5 with IStructuredSelection

use of org.eclipse.jface.viewers.IStructuredSelection in project dbeaver by serge-rider.

the class NavigatorHandlerObjectOpen method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
            Object element = iter.next();
            DBNNode node = null;
            if (element instanceof IResource) {
                openResource((IResource) element, HandlerUtil.getActiveWorkbenchWindow(event));
                continue;
            } else if (element instanceof DBNNode) {
                node = (DBNNode) element;
            } else {
                DBSObject object = RuntimeUtils.getObjectAdapter(element, DBSObject.class);
                if (object != null) {
                    node = getNodeByObject(object);
                }
            }
            if (node != null) {
                NavigatorUtils.openNavigatorNode(node, HandlerUtil.getActiveWorkbenchWindow(event));
            }
        }
    }
    return null;
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ISelection(org.eclipse.jface.viewers.ISelection) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource)

Aggregations

IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)416 ISelection (org.eclipse.jface.viewers.ISelection)135 ArrayList (java.util.ArrayList)72 GridData (org.eclipse.swt.layout.GridData)70 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)67 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)66 SelectionEvent (org.eclipse.swt.events.SelectionEvent)62 Composite (org.eclipse.swt.widgets.Composite)61 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)60 GridLayout (org.eclipse.swt.layout.GridLayout)57 List (java.util.List)50 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)45 TableViewer (org.eclipse.jface.viewers.TableViewer)41 RepositoryNode (org.talend.repository.model.RepositoryNode)41 Iterator (java.util.Iterator)39 IFile (org.eclipse.core.resources.IFile)35 Button (org.eclipse.swt.widgets.Button)35 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)32 Table (org.eclipse.swt.widgets.Table)30 Label (org.eclipse.swt.widgets.Label)29