Search in sources :

Example 46 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project netxms by netxms.

the class EventObjectList method removeFromGroup.

/**
 * Remove event object from group
 */
@SuppressWarnings("unchecked")
protected void removeFromGroup() {
    ITreeSelection selection = (ITreeSelection) viewer.getSelection();
    List<EventObject> list = selection.toList();
    for (int i = 0; i < selection.size(); i++) {
        EventGroup parent = (EventGroup) selection.getPathsFor(list.get(i))[0].getParentPath().getLastSegment();
        EventObject child = list.get(i);
        parent.removeChild(child.getCode());
        modifyEventObject(parent, false);
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) EventObject(org.netxms.client.events.EventObject) EventGroup(org.netxms.client.events.EventGroup)

Example 47 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project netxms by netxms.

the class EventObjectList method modifyEventObject.

/**
 * Modify event object in server
 *
 * @param obj to modify
 */
protected void modifyEventObject(final EventObject obj, final boolean updateParent) {
    new ConsoleJob(Messages.get().EventConfigurator_UpdateJob_Title, null, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().EventConfigurator_UpdateJob_Error;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyEventObject(obj);
            if (updateParent) {
                runInUIThread(new Runnable() {

                    /* (non-Javadoc)
                   * @see java.lang.Runnable#run()
                   */
                    @Override
                    public void run() {
                        ITreeSelection selection = (ITreeSelection) viewer.getSelection();
                        if (selection.size() == 1 && selection.getFirstElement() instanceof EventGroup) {
                            ((EventGroup) selection.getFirstElement()).addChild(obj.getCode());
                            modifyEventObject((EventGroup) selection.getFirstElement(), false);
                        }
                    }
                });
            }
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) EventGroup(org.netxms.client.events.EventGroup)

Example 48 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project n4js by eclipse.

the class N4JSProjectInWorkingSetDropAdapterAssistant method handleDrop.

@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent dropTargetEvent, Object target) {
    WorkingSet oldTarget = (WorkingSet) target;
    WorkingSetManager manager = oldTarget.getWorkingSetManager();
    List<WorkingSet> allItems = newArrayList(manager.getAllWorkingSets());
    List<WorkingSet> visibleItems = newArrayList(manager.getWorkingSets());
    WorkingSetDiffBuilder diffBuilder = new WorkingSetDiffBuilder(manager);
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof ITreeSelection) {
        ManualAssociationWorkingSet oldSource = null;
        for (TreePath path : ((ITreeSelection) selection).getPaths()) {
            IProject project = ((IAdaptable) path.getLastSegment()).getAdapter(IProject.class);
            if (project != null) {
                if (!(target instanceof ManualAssociationWorkingSet)) {
                    return CANCEL_STATUS;
                }
                if (!ManualAssociationAwareWorkingSetManager.class.getName().equals(manager.getId())) {
                    return CANCEL_STATUS;
                }
                if (!workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
                    Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
                    projectNames.add(project.getName());
                    ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
                    int allIndex = indexOfById(oldTarget, allItems);
                    allItems.remove(allIndex);
                    allItems.add(allIndex, newTarget);
                    int visibleIndex = indexOfById(oldTarget, visibleItems);
                    if (visibleIndex >= 0) {
                        visibleItems.remove(visibleIndex);
                        visibleItems.add(visibleIndex, newTarget);
                    }
                    diffBuilder.edit(oldTarget, newTarget);
                    oldTarget = newTarget;
                }
                // Check if our top-level element is a working set so that we can perform a move
                if (path.getFirstSegment() instanceof ManualAssociationWorkingSet) {
                    if (oldSource == null) {
                        oldSource = ((ManualAssociationWorkingSet) path.getFirstSegment());
                    }
                    if (oldSource != null && !OTHERS_WORKING_SET_ID.equals(oldSource.getId())) {
                        Collection<String> projectNames = newHashSet(oldSource.getAssociatedProjectNames());
                        projectNames.remove(project.getName());
                        ManualAssociationWorkingSet newSource = new ManualAssociationWorkingSet(projectNames, oldSource.getId(), manager);
                        int allIndex = indexOfById(oldSource, allItems);
                        allItems.remove(allIndex);
                        allItems.add(allIndex, newSource);
                        int visibleIndex = indexOfById(oldSource, visibleItems);
                        if (visibleIndex >= 0) {
                            visibleItems.remove(visibleIndex);
                            visibleItems.add(visibleIndex, newSource);
                        }
                        diffBuilder.edit(oldSource, newSource);
                        oldSource = newSource;
                    }
                }
            } else if (path.getLastSegment() instanceof WorkingSet) {
                WorkingSet movedWorkingSet = (WorkingSet) path.getLastSegment();
                int sourceVisibleIndex = indexOfById(movedWorkingSet, visibleItems);
                int sourceAllIndex = indexOfById(movedWorkingSet, allItems);
                if (sourceVisibleIndex == -1 || sourceAllIndex == -1) {
                    return CANCEL_STATUS;
                }
                final Object currentTarget = getCommonDropAdapter().getCurrentTarget();
                if (currentTarget instanceof WorkingSet) {
                    int targetVisibleIndex = indexOfById((WorkingSet) currentTarget, visibleItems);
                    int targetAllIndex = indexOfById((WorkingSet) currentTarget, allItems);
                    if (targetVisibleIndex == -1 || targetAllIndex == -1) {
                        return CANCEL_STATUS;
                    }
                    if (getCommonDropAdapter().getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
                        targetVisibleIndex++;
                        targetAllIndex++;
                    }
                    WorkingSet visibleRemoved = visibleItems.remove(sourceVisibleIndex);
                    visibleItems.add(sourceVisibleIndex >= targetVisibleIndex ? targetVisibleIndex : targetVisibleIndex - 1, visibleRemoved);
                    WorkingSet allRemoved = allItems.remove(sourceAllIndex);
                    allItems.add(sourceAllIndex >= targetAllIndex ? targetAllIndex : targetAllIndex - 1, allRemoved);
                } else {
                    return CANCEL_STATUS;
                }
            }
        }
    } else if (selection instanceof IStructuredSelection) {
        for (Object item : ((IStructuredSelection) selection).toArray()) {
            IProject project = ((IAdaptable) item).getAdapter(IProject.class);
            if (project != null && !workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
                Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
                projectNames.add(project.getName());
                ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
                allItems.remove(oldTarget);
                allItems.add(newTarget);
                if (visibleItems.remove(oldTarget)) {
                    visibleItems.add(newTarget);
                }
                diffBuilder.edit(oldTarget, newTarget);
                oldTarget = newTarget;
            }
        }
    }
    WorkingSet[] newItems = Iterables.toArray(visibleItems, WorkingSet.class);
    WorkingSet[] newAllItems = Iterables.toArray(allItems, WorkingSet.class);
    Diff<WorkingSet> diff = diffBuilder.build(newItems, newAllItems);
    if (!diff.isEmpty()) {
        manager.updateState(diff);
        manager.saveState(new NullProgressMonitor());
        workingSetManagerBroker.refreshNavigator();
    }
    return OK_STATUS;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) IProject(org.eclipse.core.resources.IProject) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) TreePath(org.eclipse.jface.viewers.TreePath) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ISelection(org.eclipse.jface.viewers.ISelection) Collection(java.util.Collection) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)

Example 49 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project liferay-ide by liferay.

the class CustomJspPage method _createLeftPart.

private void _createLeftPart(Composite parent) {
    ScrolledComposite leftContainer = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite leftPart = SWTUtil.createComposite(leftContainer, 1, 1, GridData.FILL_BOTH, 0, 0);
    FillLayout layout = new FillLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    leftContainer.setLayout(layout);
    leftContainer.setMinSize(410, 200);
    leftContainer.setExpandHorizontal(true);
    leftContainer.setExpandVertical(true);
    leftContainer.setContent(leftPart);
    Label leftLabel = new Label(leftPart, SWT.NONE);
    leftLabel.setText("6.2 Custom JSPs (double-click to compare with 6.2)");
    _leftTreeViewer = new TreeViewer(leftPart, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    _leftTreeViewer.getTree().setLayoutData(gd);
    _leftTreeViewer.setContentProvider(new ViewContentProvider());
    _leftTreeViewer.setLabelProvider(new LeftViewLabelProvider());
    _leftTreeViewer.addDoubleClickListener(new DoubleClickExpandListener(_leftTreeViewer));
    _leftTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            ISelection selection = event.getSelection();
            File file = (File) ((ITreeSelection) selection).getFirstElement();
            if (file.isDirectory()) {
                return;
            }
            if (_is62FileFound(file)) {
                String[] paths = _get62FilePaths(file);
                compare(paths[0], paths[1], "6.2 original JSP", "custom JSP");
            } else {
                MessageDialog.openInformation(Display.getDefault().getActiveShell(), "File not found", "There is no such file in liferay 62");
            }
        }
    });
    _leftTreeViewer.setComparator(new ViewerComparator() {

        @Override
        public int category(Object element) {
            File file = (File) element;
            if (file.isDirectory()) {
                return -1;
            } else {
                return super.category(element);
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 50 with ITreeSelection

use of org.eclipse.jface.viewers.ITreeSelection in project jbosstools-hibernate by jbosstools.

the class IndexToolkitViewLaunchHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getActiveMenuSelection(event);
    if (sel.isEmpty()) {
        return null;
    }
    ITreeSelection selection = (ITreeSelection) sel;
    if (selection.getFirstElement() instanceof ConsoleConfiguration) {
        ConsoleConfiguration consoleConfig = (ConsoleConfiguration) selection.getFirstElement();
        if (ConsoleConfigurationUtils.isConnectionExist(consoleConfig)) {
            HibernateSearchConsolePlugin.getDefault().showIndexToolkitView(consoleConfig);
        }
    }
    return null;
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ISelection(org.eclipse.jface.viewers.ISelection)

Aggregations

ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)56 TreePath (org.eclipse.jface.viewers.TreePath)17 ISelection (org.eclipse.jface.viewers.ISelection)16 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 ArrayList (java.util.ArrayList)7 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)7 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)7 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 IErlFunction (org.erlide.engine.model.erlang.IErlFunction)5 IProject (org.eclipse.core.resources.IProject)4 IStatus (org.eclipse.core.runtime.IStatus)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 GridData (org.eclipse.swt.layout.GridData)4 Composite (org.eclipse.swt.widgets.Composite)4 TracePattern (org.erlide.tracing.core.mvc.model.TracePattern)4 Test (org.junit.Test)4 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)3 URL (java.net.URL)3 HashSet (java.util.HashSet)3