Search in sources :

Example 6 with IContentProvider

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);
    }
}
Also used : IContentProvider(org.eclipse.jface.viewers.IContentProvider) DeferredContentProvider(com.cubrid.common.ui.common.navigator.DeferredContentProvider) CubridDeferredTreeContentManager(com.cubrid.common.ui.common.navigator.CubridDeferredTreeContentManager)

Example 7 with IContentProvider

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();
            }
        }
    });
}
Also used : IContentProvider(org.eclipse.jface.viewers.IContentProvider) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) CellGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider) Dimension(java.awt.Dimension) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) Graph(org.eclipse.zest.core.widgets.Graph) FileOutputStream(java.io.FileOutputStream) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Display(org.eclipse.swt.widgets.Display)

Example 8 with IContentProvider

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;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) GroovyColorManager(eu.esdihumboldt.hale.ui.util.groovy.GroovyColorManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) IColorManager(eu.esdihumboldt.hale.ui.util.IColorManager) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) SchemaPatternFilter(eu.esdihumboldt.hale.ui.common.definition.viewer.SchemaPatternFilter) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) StyledDefinitionLabelProvider(eu.esdihumboldt.hale.ui.common.definition.viewer.StyledDefinitionLabelProvider) SimpleGroovySourceViewerConfiguration(eu.esdihumboldt.hale.ui.util.groovy.SimpleGroovySourceViewerConfiguration) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with IContentProvider

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);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IContentProvider(org.eclipse.jface.viewers.IContentProvider) RepositoriesViewContentProvider(org.eclipse.egit.ui.internal.repository.RepositoriesViewContentProvider) BranchHierarchyNode(org.eclipse.egit.ui.internal.repository.tree.BranchHierarchyNode) RefNode(org.eclipse.egit.ui.internal.repository.tree.RefNode) AdditionalRefNode(org.eclipse.egit.ui.internal.repository.tree.AdditionalRefNode)

Example 10 with IContentProvider

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;
}
Also used : CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) IViewPart(org.eclipse.ui.IViewPart) IContentProvider(org.eclipse.jface.viewers.IContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

IContentProvider (org.eclipse.jface.viewers.IContentProvider)15 IRepositoryNode (org.talend.repository.model.IRepositoryNode)5 RepositoryNode (org.talend.repository.model.RepositoryNode)5 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)4 TreeViewer (org.eclipse.jface.viewers.TreeViewer)4 Item (org.talend.core.model.properties.Item)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 ProjectRepositoryNode (org.talend.core.repository.model.ProjectRepositoryNode)4 Composite (org.eclipse.swt.widgets.Composite)3 TableItem (org.eclipse.swt.widgets.TableItem)3 TreePathFilteredTree (eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree)2 ArrayList (java.util.ArrayList)2 Property (org.talend.core.model.properties.Property)2 RepositoryObject (org.talend.core.model.repository.RepositoryObject)2 IProjectRepositoryNode (org.talend.repository.model.nodes.IProjectRepositoryNode)2 CubridDeferredTreeContentManager (com.cubrid.common.ui.common.navigator.CubridDeferredTreeContentManager)1 DeferredContentProvider (com.cubrid.common.ui.common.navigator.DeferredContentProvider)1 Category (eu.esdihumboldt.cst.functions.groovy.helper.Category)1 HelperFunctionOrCategory (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionOrCategory)1 HelperFunctionsService (eu.esdihumboldt.cst.functions.groovy.helper.HelperFunctionsService)1