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);
}
}
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();
}
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;
}
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);
}
}
});
}
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;
}
Aggregations