use of org.eclipse.jface.viewers.IContentProvider in project cubrid-manager by CUBRID.
the class CommonUITool method refreshNavigatorTree.
/**
*
* Reload the children of this node and restore the expanded status
*
* @param viewer the TableViewer object
* @param node the ICubridNode object
*/
public static void refreshNavigatorTree(AbstractTreeViewer viewer, ICubridNode node) {
if (node != null && node.getLoader() != null) {
node.getLoader().setLoaded(false);
}
if (node != null && !viewer.getExpandedState(node)) {
node.removeAllChild();
}
Object[] expandedElements = viewer.getExpandedElements();
IContentProvider contentProvider = viewer.getContentProvider();
if (contentProvider instanceof DeferredContentProvider) {
CubridDeferredTreeContentManager manager = ((DeferredContentProvider) contentProvider).getDeferredTreeContentManager();
if (manager != null) {
manager.setExpandedElements(expandedElements);
}
}
if (node == null) {
viewer.refresh(true);
} else {
viewer.refresh(node, true);
}
}
use of org.eclipse.jface.viewers.IContentProvider in project hale by halestudio.
the class HtmlMappingExporter method saveImageToFile.
private void saveImageToFile(final Cell cell, File filesDir) {
Display display;
if (Display.getCurrent() != null) {
// use the current display if available
display = Display.getCurrent();
} else {
try {
// use workbench display if available
display = PlatformUI.getWorkbench().getDisplay();
} catch (Throwable e) {
// use a dedicated display thread if no workbench is
// available
display = DisplayThread.getInstance().getDisplay();
}
}
// creates a unique id for each cell
String cellId = cellIds.getId(cell);
final File file = new File(filesDir, "img_" + cellId + ".png");
display.syncExec(new Runnable() {
@Override
public void run() {
OffscreenGraph offscreenGraph = new OffscreenGraph(600, 200) {
@Override
protected void configureViewer(GraphViewer viewer) {
IContentProvider contentProvider = new CellGraphContentProvider();
GraphLabelProvider labelProvider = new GraphLabelProvider(null, HaleUI.getServiceProvider());
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(labelProvider);
viewer.setInput(cell);
}
};
Graph graph = offscreenGraph.getGraph();
Dimension dimension = computeSize(graph);
// minimum width = 600
offscreenGraph.resize(dimension.width > 600 ? dimension.width : 600, dimension.height);
try {
offscreenGraph.saveImage(new BufferedOutputStream(new FileOutputStream(file)), null);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Can not create image", e));
} finally {
offscreenGraph.dispose();
}
}
});
}
use of org.eclipse.jface.viewers.IContentProvider in project hale by halestudio.
the class TypeStructureTray method createContents.
@Override
protected Control createContents(Composite parent) {
Composite page = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(page);
// retrieve the types
final Collection<? extends TypeDefinition> types = this.types.getTypes();
// heading
Label caption = new Label(page, SWT.NONE);
switch(schemaSpace) {
case SOURCE:
caption.setText("Source structure");
break;
case TARGET:
caption.setText("Target structure");
break;
}
caption.setFont(JFaceResources.getHeaderFont());
// create tree viewer
PatternFilter patternFilter = new SchemaPatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
final FilteredTree filteredTree = new TreePathFilteredTree(page, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
TreeViewer tree = filteredTree.getViewer();
tree.setUseHashlookup(true);
StyledDefinitionLabelProvider labelProvider = new StyledDefinitionLabelProvider(tree);
tree.setLabelProvider(labelProvider);
IContentProvider contentProvider = createContentProvider(tree);
tree.setContentProvider(contentProvider);
GridDataFactory.fillDefaults().grab(true, true).hint(280, 400).applyTo(filteredTree);
tree.setComparator(new DefinitionComparator());
// set input
if (types.size() == 1) {
tree.setInput(types.iterator().next());
} else {
tree.setInput(types);
}
/*
* Groovy specific part
*/
// caption
Label example = new Label(page, SWT.NONE);
switch(schemaSpace) {
case SOURCE:
example.setText("Examples: Access variables");
break;
case TARGET:
example.setText("Example: Build instance");
break;
default:
example.setText("Example");
}
// source viewer
final SourceViewer viewer = new SourceViewer(page, null, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
final IColorManager colorManager = new GroovyColorManager();
SourceViewerConfiguration configuration = new SimpleGroovySourceViewerConfiguration(colorManager, ImmutableList.of(BINDING_TARGET, BINDING_BUILDER, BINDING_INDEX, BINDING_SOURCE, BINDING_SOURCE_TYPES, BINDING_TARGET_TYPE, BINDING_CELL, BINDING_LOG, BINDING_CELL_CONTEXT, BINDING_FUNCTION_CONTEXT, BINDING_TRANSFORMATION_CONTEXT), null);
viewer.configure(configuration);
GridDataFactory.fillDefaults().grab(true, false).hint(200, 130).applyTo(viewer.getControl());
// make sure the color manager is disposed
viewer.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
colorManager.dispose();
}
});
// react to tree selection changes
tree.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IDocument doc = new Document();
GroovySourceViewerUtil.setupDocument(doc);
String example = null;
if (!event.getSelection().isEmpty()) {
switch(schemaSpace) {
case SOURCE:
example = createSourceSample(event.getSelection(), types);
break;
case TARGET:
example = createTargetSample(event.getSelection(), types);
break;
}
}
if (example == null || example.isEmpty()) {
switch(schemaSpace) {
case SOURCE:
doc.set("// Please select schema elements to access");
break;
case TARGET:
doc.set("// Please select which schema elements\n// to include in the instance to build");
break;
default:
doc.set("// Please select one or more schema elements");
}
} else {
doc.set(example);
}
viewer.setDocument(doc);
}
});
tree.setSelection(StructuredSelection.EMPTY);
return page;
}
use of org.eclipse.jface.viewers.IContentProvider in project egit by eclipse.
the class AbstractBranchSelectionDialog method createRefNode.
private RefNode createRefNode(RepositoryTreeNode<?> root, Repository repository, Ref ref) {
IContentProvider cp = branchTree.getContentProvider();
if (cp instanceof RepositoriesViewContentProvider && ((RepositoriesViewContentProvider) cp).isHierarchical()) {
// Create intermediary BranchHierarchyNodes
String fullName = ref.getName();
int i = 0;
if (fullName.startsWith(Constants.R_HEADS)) {
i = Constants.R_HEADS.length();
} else if (fullName.startsWith(Constants.R_REMOTES)) {
i = Constants.R_REMOTES.length();
}
RepositoryTreeNode<?> top = root;
int l = fullName.length();
while (i < l) {
int j = fullName.indexOf('/', i);
if (j > i) {
top = new BranchHierarchyNode(top, repository, new Path(fullName.substring(0, j)));
i = j + 1;
} else {
break;
}
}
return new RefNode(top, repository, ref);
} else {
return new RefNode(root, repository, ref);
}
}
use of org.eclipse.jface.viewers.IContentProvider in project jbosstools-openshift by jbosstools.
the class OpenShiftUIUtils method getConnectionForExplorerSelection.
/**
* Returns the connection for the given type and current selection in the OpenShift explorer.
*
* @param klass connection type
* @return
*/
public static <T extends IConnection> T getConnectionForExplorerSelection(Class<T> klass) {
ISelection selection = getOpenShiftExplorerSelection();
if (selection != null && !selection.isEmpty()) {
T result = UIUtils.getFirstElement(selection, klass);
IViewPart part = getOpenShiftExplorer();
if (result == null && selection instanceof IStructuredSelection && part instanceof CommonNavigator) {
Object selected = ((IStructuredSelection) selection).getFirstElement();
IContentProvider provider = ((CommonNavigator) part).getCommonViewer().getContentProvider();
if (provider instanceof ITreeContentProvider) {
ITreeContentProvider tree = (ITreeContentProvider) provider;
while (selected != null && result == null) {
result = UIUtils.adapt(selected, klass);
selected = tree.getParent(selected);
}
}
}
return result;
}
return null;
}
Aggregations