use of org.eclipse.jface.viewers.ITreeSelection in project hale by halestudio.
the class PropertyEntityDialog method getObjectFromSelection.
/**
* @see EntityDialog#getObjectFromSelection(ISelection)
*/
@Override
protected EntityDefinition getObjectFromSelection(ISelection selection) {
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof EntityDefinition) {
return (EntityDefinition) element;
}
}
if (!selection.isEmpty() && selection instanceof ITreeSelection) {
// create property definition w/ default contexts
TreePath path = ((ITreeSelection) selection).getPaths()[0];
// get parent type
TypeDefinition type = ((PropertyDefinition) path.getFirstSegment()).getParentType();
// determine definition path
List<ChildContext> defPath = new ArrayList<ChildContext>();
for (int i = 0; i < path.getSegmentCount(); i++) {
defPath.add(new ChildContext((ChildDefinition<?>) path.getSegment(i)));
}
// TODO check if property entity definition is applicable?
return new PropertyEntityDefinition(type, defPath, ssid, parentType.getFilter());
}
return null;
}
use of org.eclipse.jface.viewers.ITreeSelection in project hale by halestudio.
the class InstanceValidationReportDetailsPage method getValidSelection.
/**
* Returns a valid instance selection for the current selection of the tree
* viewer. Returns <code>null</code> if there is none.
*
* @return a valid instance selection for the current selection of the tree
* viewer or <code>null</code>
*/
private InstanceSelection getValidSelection() {
ISelection viewerSelection = treeViewer.getSelection();
if (!(viewerSelection instanceof ITreeSelection) || viewerSelection.isEmpty())
return null;
ITreeSelection treeSelection = (ITreeSelection) treeViewer.getSelection();
// XXX use all paths
TreePath firstPath = treeSelection.getPaths()[0];
// instead of first
// only?
InstanceValidationMessage firstMessage;
Iterator<InstanceValidationMessage> restIter;
if (firstPath.getLastSegment() instanceof InstanceValidationMessage) {
firstMessage = (InstanceValidationMessage) firstPath.getLastSegment();
restIter = Collections.emptyIterator();
} else {
Collection<InstanceValidationMessage> messages = contentProvider.getMessages(treeSelection.getPaths()[0]);
if (messages.isEmpty())
// shouldn't happen, but doesn't really matter
return null;
restIter = messages.iterator();
firstMessage = restIter.next();
}
InstanceService is = PlatformUI.getWorkbench().getService(InstanceService.class);
// check first message for valid instance reference
if (firstMessage.getInstanceReference() == null || is.getInstance(firstMessage.getInstanceReference()) == null)
return null;
Set<InstanceReference> references = new HashSet<InstanceReference>();
references.add(firstMessage.getInstanceReference());
while (restIter.hasNext()) references.add(restIter.next().getInstanceReference());
return new DefaultInstanceSelection(references.toArray());
}
use of org.eclipse.jface.viewers.ITreeSelection in project hale by halestudio.
the class TypeStructureTray method createSourceSample.
/**
* Create sample code for accessing a source property.
*
* @param selection the selection in the tree viewer
* @param types the types serving as input
* @return the sample code or <code>null</code>
*/
protected String createSourceSample(ISelection selection, Collection<? extends TypeDefinition> types) {
ITreeSelection treeSel = (ITreeSelection) selection;
TreePath[] paths = treeSel.getPaths();
if (paths != null && paths.length > 0) {
StringBuilder result = null;
for (TreePath path : paths) {
String examples = createSourceSample(path, types);
if (examples != null) {
if (result == null) {
result = new StringBuilder();
}
result.append(examples);
}
}
if (result != null) {
return result.toString();
}
return null;
}
return null;
}
use of org.eclipse.jface.viewers.ITreeSelection in project hale by halestudio.
the class TypeStructureTray method createTargetSample.
/**
* Create sample code for populating the target property.
*
* @param selection the selection in the tree viewer
* @param types the types serving as input
* @return the sample code
*/
protected String createTargetSample(ISelection selection, Collection<? extends TypeDefinition> types) {
ITreeSelection treeSel = (ITreeSelection) selection;
TreePath[] paths = treeSel.getPaths();
if (paths != null && paths.length > 0) {
// XXX for now only use the first path
TreePath path = paths[0];
DefinitionGroup parent;
int startIndex = 0;
List<PathTree> properties;
// determine parent type
if (path.getFirstSegment() instanceof TypeDefinition) {
// XXX not supported yet
return null;
} else {
// types are not in the tree, single type must be root
parent = types.iterator().next();
// build PathTrees from tree paths
properties = PathTree.createPathTrees(Arrays.asList(paths), startIndex);
}
StringBuilder example = new StringBuilder();
example.append(GroovyConstants.BINDING_TARGET);
example.append(" {\n");
int indentCount = 1;
for (PathTree tree : properties) {
InstanceBuilderCode.appendBuildProperties(example, indentCount, tree, parent, BUILDER_USE_BRACKETS);
}
example.append("}");
return example.toString();
}
return GroovyConstants.BINDING_TARGET + " = {}";
}
use of org.eclipse.jface.viewers.ITreeSelection in project meclipse by flaper87.
the class FilterWizard method addFilter.
public void addFilter(ISelection selection, Filter filter) {
if (selection == null)
throw new IllegalStateException(getCaption("filterWizard.error.nullSelection"));
if (!(selection instanceof ITreeSelection))
throw new IllegalStateException(selection.getClass().getSimpleName() + getCaption("filterWizard.error.noITreeSelection"));
ITreeSelection treeSelection = (ITreeSelection) selection;
Object obj = treeSelection.getFirstElement();
if (!(obj instanceof Collection) && !(obj instanceof Filter))
throw new IllegalStateException(obj.getClass().getSimpleName() + getCaption("filterWizard.error.noCollection"));
TreeParent parent = (TreeParent) obj;
filter.setParent(parent);
MeclipsePlugin.getDefault().addFilter(new FilterPlacement(parent), filter);
}
Aggregations