Java Code Examples for org.eclipse.jface.viewers.TreePath#getLastSegment()

The following examples show how to use org.eclipse.jface.viewers.TreePath#getLastSegment() . 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: LogContent.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void copyTreeSelectionToClipboard() {
  ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();
  TreePath[] paths = selection.getPaths();

  StringBuffer buf = new StringBuffer();

  for (TreePath path : paths) {
    LogEntry<?> entry = (LogEntry<?>) path.getLastSegment();
    buf.append(createTabString(path.getSegmentCount() - 1));
    buf.append(entry.toString());
    buf.append("\n");
  }

  if (buf.length() > 0) {
    buf.deleteCharAt(buf.length() - 1); // take off last \n
  }

  copyToClipboard(buf.toString());
}
 
Example 2
Source File: JavaSynchronizationLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void updateLabel(ViewerLabel label, TreePath elementPath) {
	Object firstSegment = elementPath.getFirstSegment();
	if (firstSegment instanceof IProject && elementPath.getSegmentCount() == 2) {
		IProject project = (IProject) firstSegment;
		Object lastSegment = elementPath.getLastSegment();
		if (lastSegment instanceof IFolder) {
			IFolder folder = (IFolder) lastSegment;
			if (!folder.getParent().equals(project)) {
				// This means that a folder that is not a direct child of the project
				// is a child in the tree. Therefore, the resource content provider
				// must be active and in compress folder mode so we will leave
				// it to the resource provider to provide the proper label.
				// We need to do this because of bug 153912
				return;
			}
		}
	}
	label.setImage(getImage(elementPath.getLastSegment()));
	label.setText(getText(elementPath.getLastSegment()));
	Font f = getFont(elementPath.getLastSegment());
	if (f != null)
		label.setFont(f);
}
 
Example 3
Source File: PyPackageStateSaver.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Saves some selection in the memento object.
 */
private void save(TreePath treePath, String type) {
    if (treePath != null) {
        Object object = treePath.getLastSegment();
        if (object instanceof IAdaptable) {
            IAdaptable adaptable = (IAdaptable) object;
            IResource resource = (IResource) adaptable.getAdapter(IResource.class);
            if (resource != null) {
                IPath path = resource.getLocation();
                if (path != null) {
                    memento.createChild(type, path.toPortableString());
                }
            }
        }
    }
}
 
Example 4
Source File: CrossflowNavigatorLabelProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
* @generated
*/
public void updateLabel(ViewerLabel label, TreePath elementPath) {
	Object element = elementPath.getLastSegment();
	if (element instanceof CrossflowNavigatorItem && !isOwnView(((CrossflowNavigatorItem) element).getView())) {
		return;
	}
	label.setText(getText(element));
	label.setImage(getImage(element));
}
 
Example 5
Source File: TypeScriptFilter.java    From typescript.java with MIT License 5 votes vote down vote up
private boolean hasParentTypeScriptFile(Object parent) {
	if (parent instanceof TreePath) {
		TreePath treePath = (TreePath) parent;
		Object segment = treePath.getLastSegment();
		if (segment == null) {
			return false;
		}
		return TypeScriptResourceUtil.isTsOrTsxFile(segment);
	}
	return false;
}
 
Example 6
Source File: DiagramPartitioningEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public void updateLabel(ViewerLabel label, TreePath elementPath) {
	Diagram lastSegment = (Diagram) elementPath.getLastSegment();
	NamedElement element = (NamedElement) lastSegment.getElement();
	AdapterFactoryLabelProvider provider = new AdapterFactoryLabelProvider(
			new SGraphItemProviderAdapterFactory());
	label.setText(provider.getText(element));
	if (element instanceof Statechart)
		label.setImage(StatechartImages.LOGO.image());
	else
		label.setImage(provider.getImage(element));

}
 
Example 7
Source File: NavigatorFilter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
	if (parentElement instanceof TreePath && ResourceManager.isFile(element)) {
		final TreePath p = (TreePath) parentElement;
		if (p.getLastSegment() instanceof WrappedFolder) {
			final IResource r = FileMetaDataProvider.shapeFileSupportedBy(ResourceManager.getFile(element));
			if (r != null) { return false; }
		}
	}
	return true;
}
 
Example 8
Source File: UserLibraryPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath getWorkbenchWindowSelection() {
	IWorkbenchWindow window= fWorkbench.getActiveWorkbenchWindow();
	if (window != null) {
		ISelection selection= window.getSelectionService().getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection= (IStructuredSelection) selection;
			Object element= structuredSelection.getFirstElement();
			if (element != null) {
				Object resource= Platform.getAdapterManager().getAdapter(element, IResource.class);
				if (resource != null) {
					return ((IResource) resource).getFullPath();
				}
				if (structuredSelection instanceof ITreeSelection) {
					TreePath treePath= ((ITreeSelection) structuredSelection).getPaths()[0];
					while ((treePath = treePath.getParentPath()) != null) {
						element= treePath.getLastSegment();
						resource= Platform.getAdapterManager().getAdapter(element, IResource.class);
						if (resource != null) {
							return ((IResource) resource).getFullPath();
						}
					}
				}
			}
			
		}
	}
	return null;
}
 
Example 9
Source File: SelectPathDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param path
 * @param useQualifiedName TODO
 * @return
 */
public static String computeXPath(TreePath path, boolean useQualifiedName) {
	StringBuilder pathBuilder = new StringBuilder();
	for (int i = 1; i < path.getSegmentCount(); i++) {
		if (path.getSegment(i) instanceof XSDContentProvider.Append) {
			continue;
		}
		
		pathBuilder.append('/');
		XSDNamedComponent item = (XSDNamedComponent)path.getSegment(i);
		if (item instanceof XSDAttributeDeclaration) {
			pathBuilder.append('@');
		}
		if(useQualifiedName){
			pathBuilder.append(item.getQName());
		} else {
			pathBuilder.append(item.getName());
		}
		if (item instanceof XSDElementDeclaration) {
			XSDElementDeclaration element = (XSDElementDeclaration)item;
			if (element.getContainer() instanceof XSDParticle) {
				XSDParticle particle = (XSDParticle)element.getContainer();
				if (particle.getMaxOccurs() < 0 || particle.getMinOccurs() > 1) {
					pathBuilder.append("[1]");
				}
			}
		}
	}
	if (path.getLastSegment() instanceof XSDElementDeclaration && 
		((XSDElementDeclaration)path.getLastSegment()).getType().getSimpleType() != null) {
		pathBuilder.append("/text()");
	}
	if (path.getLastSegment() instanceof XSDContentProvider.Append) {
		pathBuilder.append(BonitaConstants.XPATH_VAR_SEPARATOR + BonitaConstants.XPATH_APPEND_FLAG);
	}
	return pathBuilder.toString();
}
 
Example 10
Source File: XPathOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected String computeXPath(TreePath path, boolean useQualifiedName) {
    StringBuilder pathBuilder = new StringBuilder();
    for (int i = 1; i < path.getSegmentCount(); i++) {
        if (path.getSegment(i) instanceof XSDContentProvider.Append) {
            continue;
        }

        pathBuilder.append('/');
        XSDNamedComponent item = (XSDNamedComponent)path.getSegment(i);
        if (item instanceof XSDAttributeDeclaration) {
            pathBuilder.append('@');
        }
        if(useQualifiedName){
            pathBuilder.append(item.getQName());
        } else {
            pathBuilder.append(item.getName());
        }
        if (item instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration)item;
            if (element.getContainer() instanceof XSDParticle) {
                XSDParticle particle = (XSDParticle)element.getContainer();
                if (particle.getMaxOccurs() < 0 || particle.getMinOccurs() > 1) {
                    pathBuilder.append("[1]");
                }
            }
        }
    }
    if (path.getLastSegment() instanceof XSDElementDeclaration &&
            ((XSDElementDeclaration)path.getLastSegment()).getType().getSimpleType() != null) {
        pathBuilder.append("/text()");
    }
    if (path.getLastSegment() instanceof XSDContentProvider.Append) {
        pathBuilder.append(BonitaConstants.XPATH_VAR_SEPARATOR + BonitaConstants.XPATH_APPEND_FLAG);
    }
    return pathBuilder.toString();
}
 
Example 11
Source File: XPathExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static String computeXPath(final TreePath path, final boolean useQualifiedName) {
    final StringBuilder pathBuilder = new StringBuilder();
    for (int i = 1; i < path.getSegmentCount(); i++) {
        if (path.getSegment(i) instanceof XSDContentProvider.Append) {
            continue;
        }

        pathBuilder.append('/');
        final XSDNamedComponent item = (XSDNamedComponent) path.getSegment(i);
        if (item instanceof XSDAttributeDeclaration) {
            pathBuilder.append('@');
        }
        if (useQualifiedName) {
            pathBuilder.append(item.getQName());
        } else {
            pathBuilder.append(item.getName());
        }
        if (item instanceof XSDElementDeclaration) {
            final XSDElementDeclaration element = (XSDElementDeclaration) item;
            if (element.getContainer() instanceof XSDParticle) {
                final XSDParticle particle = (XSDParticle) element.getContainer();
                if (particle.getMaxOccurs() < 0 || particle.getMinOccurs() > 1) {
                    pathBuilder.append("[1]");
                }
            }
        }
    }
    if (path.getLastSegment() instanceof XSDElementDeclaration &&
            ((XSDElementDeclaration) path.getLastSegment()).getType().getSimpleType() != null) {
        pathBuilder.append("/text()");
    }
    if (path.getLastSegment() instanceof XSDContentProvider.Append) {
        pathBuilder.append(BonitaConstants.XPATH_VAR_SEPARATOR + BonitaConstants.XPATH_APPEND_FLAG);
    }
    return pathBuilder.toString();
}
 
Example 12
Source File: ProcessNavigatorLabelProvider.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
* @generated
*/
public void updateLabel(ViewerLabel label, TreePath elementPath) {
	Object element = elementPath.getLastSegment();
	if (element instanceof ProcessNavigatorItem && !isOwnView(((ProcessNavigatorItem) element).getView())) {
		return;
	}
	label.setText(getText(element));
	label.setImage(getImage(element));
}
 
Example 13
Source File: ResetClasspathHandler.java    From JReFrameworker with MIT License 4 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	try {
		// get the package explorer selection
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ISelection selection = window.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");
		
		if(selection == null){
			Log.warning("Selection must be a project.");
			return null;
		}
		
		TreePath[] paths = ((TreeSelection) selection).getPaths();
		if(paths.length > 0){
			TreePath p = paths[0];
			Object last = p.getLastSegment();
			
			// locate the project handle for the selection
			IProject project = null;
			if(last instanceof IJavaProject){
				project = ((IJavaProject) last).getProject();
			} else if (last instanceof IResource) {
				project = ((IResource) last).getProject();
			} 
			
			if(project == null){
				Log.warning("Selection must be a project.");
				return null;
			}
			
			JReFrameworkerProject jrefProject = new JReFrameworkerProject(project);
			jrefProject.restoreOriginalClasspathEntries();
			jrefProject.refresh();
		} else {
			Log.warning("Selection must be a project.");
		}
	} catch (Exception e) {
		Log.error("Unable to reset project classpath", e);
	}
	
	return null;
}
 
Example 14
Source File: AddTargetHandler.java    From JReFrameworker with MIT License 4 votes vote down vote up
@SuppressWarnings("restriction")
public Object execute(ExecutionEvent event) throws ExecutionException {
	try {
		// get the package explorer selection
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		ISelection selection = window.getSelectionService().getSelection("org.eclipse.jdt.ui.PackageExplorer");
		
		if(selection == null){
			Log.warning("Selection must be a library file.");
			return null;
		}
		
		TreePath[] paths = ((TreeSelection) selection).getPaths();
		if(paths.length > 0){
			TreePath p = paths[0];
			Object last = p.getLastSegment();
			
			// locate the project handle for the selection
			IProject project = null;
			if(last instanceof IJavaProject){
				project = ((IJavaProject) last).getProject();
			} else if (last instanceof IResource) {
				project = ((IResource) last).getProject();
			} 
			
			if(last instanceof org.eclipse.core.internal.resources.File){
				File library = ((org.eclipse.core.internal.resources.File)last).getLocation().toFile();
				JReFrameworkerProject jrefProject = new JReFrameworkerProject(project);
				jrefProject.addTarget(library);
			} else {
				Log.warning("Selection must be a library file.");
			}
		} else {
			Log.warning("Selection must be a library file.");
		}
	} catch (Exception e) {
		Log.error("Unable to add target", e);
	}
	
	return null;
}