Java Code Examples for org.eclipse.jface.viewers.TreeViewer#getExpandedState()

The following examples show how to use org.eclipse.jface.viewers.TreeViewer#getExpandedState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileStagingModeUtil.java    From ADT_Frontend with MIT License 6 votes vote down vote up
public static void stageObjects(TreeViewer unstagedTreeViewer, IStructuredSelection selection, IAbapGitStaging model,
		List<Object> expandedNodes) {
	IAbapGitObject abapObject;
	IAbapGitFile file;

	movedObjects.clear();
	for (Object object : selection.toList()) {
		abapObject = null;
		file = null;
		if (object instanceof IAbapGitObject) {
			abapObject = (IAbapGitObject) object;
			if (unstagedTreeViewer.getExpandedState(abapObject)) {
				expandedNodes.add(abapObject);
			}
			stageObject(model, abapObject);
		} else if (object instanceof IAbapGitFile) {
			abapObject = (IAbapGitObject) ((IAbapGitFile) object).eContainer();
			file = (IAbapGitFile) object;
			if (movedObjects.contains(abapObject)) {
				continue;
			}
			expandedNodes.add(abapObject);
			stageFile(model, abapObject, file);
		}
	}
}
 
Example 2
Source File: FileStagingModeUtil.java    From ADT_Frontend with MIT License 6 votes vote down vote up
public static void unstageObjects(TreeViewer stagedTreeViewer, IStructuredSelection selection, IAbapGitStaging model,
		List<Object> expandedNodes) {
	IAbapGitObject abapObject;
	IAbapGitFile file;

	movedObjects.clear();
	for (Object object : selection.toList()) {
		abapObject = null;
		file = null;
		if (object instanceof IAbapGitObject) {
			abapObject = (IAbapGitObject) object;
			if (stagedTreeViewer.getExpandedState(abapObject)) {
				expandedNodes.add(abapObject);
			}
			unstageObject(model, abapObject);
		} else if (object instanceof IAbapGitFile) {
			abapObject = (IAbapGitObject) ((IAbapGitFile) object).eContainer();
			file = (IAbapGitFile) object;
			if (movedObjects.contains(abapObject)) {
				continue;
			}
			expandedNodes.add(abapObject);
			unstageFile(model, abapObject, file);
		}
	}
}
 
Example 3
Source File: ObjectStagingModeUtil.java    From ADT_Frontend with MIT License 5 votes vote down vote up
/**
 * Move selected objects from staged changes to unstaged changes
 *
 * @param selection
 *            selection from staged tree viewer
 * @param model
 *            view model
 * @param expandedNodes
 *            Will contain the list of expanded objects in the selection
 *            after the method execution
 */
public static void unstageObjects(TreeViewer stagedTreeViewer, IStructuredSelection selection, IAbapGitStaging model,
		List<Object> expandedNodes) {

	IAbapGitObject abapObject = null;
	IAbapGitFile file = null;
	for (Object object : selection.toList()) {
		abapObject = null;
		file = null;
		if (object instanceof IAbapGitObject) {
			//if selection is an object
			abapObject = (IAbapGitObject) object;
			if (abapObject.getType() == null) {
				//if non-code and meta files node, enable single file drag and drop mode
				FileStagingModeUtil.unstageObject(model, abapObject);
			} else {
				//move the object from staged changes to the unstaged changes
				model.getStagedObjects().getAbapgitobject().remove(abapObject);
				model.getUnstagedObjects().getAbapgitobject().add(abapObject);
			}
		} else if (object instanceof IAbapGitFile) {
			//if selection is a file
			file = (IAbapGitFile) object;
			//get parent object
			abapObject = (IAbapGitObject) ((IAbapGitFile) object).eContainer();
			if (abapObject.getType() == null) {
				//if non-code and meta files node, enable single file drag and drop mode
				FileStagingModeUtil.unstageFile(model, abapObject, file);
			} else {
				//move the object from staged changes to the unstaged changes
				model.getStagedObjects().getAbapgitobject().remove(abapObject);
				model.getUnstagedObjects().getAbapgitobject().add(abapObject);
			}
		}
		//get expanded state of the selected object
		if (stagedTreeViewer.getExpandedState(abapObject)) {
			expandedNodes.add(abapObject);
		}
	}
}
 
Example 4
Source File: ObjectStagingModeUtil.java    From ADT_Frontend with MIT License 4 votes vote down vote up
/**
 * Move selected objects from unstaged changes to staged changes
 *
 * @param selection
 *            selection from unstaged tree viewer
 * @param model
 *            view model
 * @param expandedNodes
 *            Will contain the list of expanded objects in the selection
 *            after the method execution
 */
public static void stageObjects(TreeViewer unstagedTreeViewer, IStructuredSelection selection, IAbapGitStaging model,
		List<Object> expandedNodes) {

	IAbapGitObject abapObject = null;
	IAbapGitFile file = null;
	for (Object object : selection.toList()) {
		abapObject = null;
		file = null;
		if (object instanceof IAbapGitObject) {
			//if selection is an object
			abapObject = (IAbapGitObject) object;
			if (abapObject.getType() == null) {
				//if non-code and meta files node, enable single file drag and drop mode
				FileStagingModeUtil.stageObject(model, abapObject);
			} else {
				//move the object from unstaged changes to the staged changes
				model.getUnstagedObjects().getAbapgitobject().remove(abapObject);
				model.getStagedObjects().getAbapgitobject().add(abapObject);
			}
		} else if (object instanceof IAbapGitFile) {
			//if selection is a file
			file = (IAbapGitFile) object;
			//get parent object
			abapObject = (IAbapGitObject) ((IAbapGitFile) object).eContainer();
			if (abapObject.getType() == null) {
				//if non-code and meta files node, enable single file drag and drop mode
				FileStagingModeUtil.stageFile(model, abapObject, file);
			} else {
				//move the object from unstaged changes to the staged changes
				model.getUnstagedObjects().getAbapgitobject().remove(abapObject);
				model.getStagedObjects().getAbapgitobject().add(abapObject);
			}
		}
		//get expanded state of the selected object
		if (unstagedTreeViewer.getExpandedState(abapObject)) {
			expandedNodes.add(abapObject);
		}
	}

}
 
Example 5
Source File: RecordToSourceCoupler.java    From tlaplus with MIT License 4 votes vote down vote up
private void performSourceCoupling(final ISelection selection, final boolean jumpToPCal, final boolean dueToArrowKeys) {
	if (selection != null && !selection.isEmpty()) {
		if (selection instanceof StructuredSelection) {
			final StructuredSelection structuredSelection = (StructuredSelection) selection;
			// on a double click there should not be multiple selections,
			// so taking the first element of the structured selection
			// should work
			final Object firstElement = structuredSelection.getFirstElement();
			if (firstElement instanceof LoaderTLCState) {
				final LoaderTLCState loader = (LoaderTLCState) firstElement;
				// Loading more states can potentially block for a couple
				// seconds. Thus, give feedback to user.
				BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
					public void run() {
						loader.loadMore();
					}
				});
			} else if (firstElement instanceof IModuleLocatable) {
				final IModuleLocatable moduleLocatable = (IModuleLocatable) firstElement;
				Location location = moduleLocatable.getModuleLocation();
				if (moduleLocatable instanceof ActionInformationItem) {
					ActionInformationItem aii = (ActionInformationItem) moduleLocatable;
					if (aii.hasDefinition()) {
						// Do not jump to a sub-actions identifier but to its actual definition if a
						// sub-action has a definition. Consider this partial spec:
						// ...
						// Next == \/ /\ x = 42
						//            /\ x' = 23
						//         \/ /\ x = 23
						//            /\ x' = 4711
						// ...
					    // getModuleLocation called on the ActionInformationItem for sub-action
						// "x = 42 /\ x' = 23" returns the location of  "x = 42 /\ x' = 23" and not
						// that of "Next".
						// This relevant in the Sub-actions for next-state table of the Model Checking
						// Results page.
						location = aii.getDefinition();
					}
				}
				if (location != null) {
					/*
					 * jumpToNested will be true if the location could be
					 * shown in a nested saved module editor. If it is
					 * false, we jump to the regular TLA editor instead.
					 */
					Model model = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class).getModel(moduleLocatable
							.getModelName());
					if (!TLCUIHelper.jumpToSavedLocation(location, model, blacklist)) {
						final IWorkbenchPart iwp;
						if (dueToArrowKeys || FocusRetentionPolicy.ALWAYS.equals(focusRetentionPolicy)) {
							iwp = partToRefocus;
						} else {
							iwp = null;
						}
						UIHelper.jumpToLocation(location, jumpToPCal, iwp);
						
						if (iwp != null) {
							viewer.getControl().getDisplay().asyncExec(() -> {
								viewer.getControl().forceFocus();
							});
						}
					}
				}
			} else if (!Platform.getWS().equals(Platform.WS_WIN32) && viewer instanceof TreeViewer) {
				// Windows has built-in expand/collapse on double click
				TreeViewer treeViewer = (TreeViewer) viewer;
				if (treeViewer.getExpandedState(firstElement)) {
					treeViewer.collapseToLevel(firstElement, 1);
				} else {
					treeViewer.expandToLevel(firstElement, 1);
				}
			}
		}
	}
}