Search in sources :

Example 1 with GraphLabelProvider

use of eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider 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 2 with GraphLabelProvider

use of eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider in project hale by halestudio.

the class AlignmentView method createLabelProvider.

/**
 * @see AbstractMappingView#createLabelProvider(GraphViewer)
 */
@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
    return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#isInherited(eu.esdihumboldt.hale.common.align.model.Cell)
         */
        @Override
        protected boolean isInherited(Cell cell) {
            // cannot inherit type cells
            if (AlignmentUtil.isTypeCell(cell))
                return false;
            return AlignmentUtil.reparentCell(cell, sourceTargetSelector.getSelectedCell(), true) != cell;
        }

        private final Color cellDisabledBackgroundColor = new Color(Display.getCurrent(), 240, 240, 240);

        private final Color cellDisabledForegroundColor = new Color(Display.getCurrent(), 109, 109, 132);

        private final Color cellDisabledHighlightColor = new Color(Display.getCurrent(), (int) (getCellHighlightColor().getRed() * 0.7), (int) (getCellHighlightColor().getGreen() * 0.7), (int) (getCellHighlightColor().getBlue() * 0.7));

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#getNodeHighlightColor(java.lang.Object)
         */
        @Override
        public Color getNodeHighlightColor(Object entity) {
            if (entity instanceof Cell && isDisabledForCurrentType((Cell) entity))
                return cellDisabledHighlightColor;
            return super.getNodeHighlightColor(entity);
        }

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#getBackgroundColour(java.lang.Object)
         */
        @Override
        public Color getBackgroundColour(Object entity) {
            if (entity instanceof Cell && isDisabledForCurrentType((Cell) entity))
                return cellDisabledBackgroundColor;
            return super.getBackgroundColour(entity);
        }

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#getForegroundColour(java.lang.Object)
         */
        @Override
        public Color getForegroundColour(Object entity) {
            if (entity instanceof Cell && isDisabledForCurrentType((Cell) entity))
                return cellDisabledForegroundColor;
            return super.getForegroundColour(entity);
        }

        /**
         * @see eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider#dispose()
         */
        @Override
        public void dispose() {
            cellDisabledBackgroundColor.dispose();
            cellDisabledForegroundColor.dispose();
            cellDisabledHighlightColor.dispose();
            super.dispose();
        }
    };
}
Also used : GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) Color(org.eclipse.swt.graphics.Color) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) BaseAlignmentCell(eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell) Cell(eu.esdihumboldt.hale.common.align.model.Cell)

Example 3 with GraphLabelProvider

use of eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider in project hale by halestudio.

the class MappingView method createLabelProvider.

@Override
protected IBaseLabelProvider createLabelProvider(GraphViewer viewer) {
    return new GraphLabelProvider(viewer, HaleUI.getServiceProvider()) {

        @Override
        protected boolean isInherited(Cell cell) {
            // cannot inherit type cells
            if (AlignmentUtil.isTypeCell(cell))
                return false;
            SchemaSelection selection = SchemaSelectionHelper.getSchemaSelection();
            if (selection != null && !selection.isEmpty()) {
                DefaultCell dummyTypeCell = new DefaultCell();
                ListMultimap<String, Type> sources = ArrayListMultimap.create();
                ListMultimap<String, Type> targets = ArrayListMultimap.create();
                Pair<Set<EntityDefinition>, Set<EntityDefinition>> items = getDefinitionsFromSelection(selection);
                for (EntityDefinition def : items.getFirst()) sources.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
                for (EntityDefinition def : items.getSecond()) targets.put(null, new DefaultType(AlignmentUtil.getTypeEntity(def)));
                dummyTypeCell.setSource(sources);
                dummyTypeCell.setTarget(targets);
                return AlignmentUtil.reparentCell(cell, dummyTypeCell, true) != cell;
            } else
                return false;
        }
    };
}
Also used : EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Type(eu.esdihumboldt.hale.common.align.model.Type) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) HashSet(java.util.HashSet) Set(java.util.Set) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell) DefaultType(eu.esdihumboldt.hale.common.align.model.impl.DefaultType) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) SchemaSelection(eu.esdihumboldt.hale.ui.selection.SchemaSelection) Cell(eu.esdihumboldt.hale.common.align.model.Cell) DefaultCell(eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)

Example 4 with GraphLabelProvider

use of eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider in project hale by halestudio.

the class TypeCellSelectionDialog method setupViewer.

/**
 * @see eu.esdihumboldt.hale.ui.util.selector.AbstractViewerSelectionDialog#setupViewer(org.eclipse.jface.viewers.StructuredViewer,
 *      java.lang.Object)
 */
@Override
protected void setupViewer(final GraphViewer viewer, Cell initialSelection) {
    // content and label provider
    viewer.setContentProvider(new ReverseCellGraphContentProvider());
    viewer.setLabelProvider(new GraphLabelProvider(viewer, HaleUI.getServiceProvider()));
    // layout
    final TreeLayoutAlgorithm layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
    viewer.getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            int width = viewer.getControl().getSize().x;
            layout.setNodeSpace(new Dimension((width - 10) / 3, 30));
        }
    });
    viewer.setLayoutAlgorithm(layout, true);
    viewer.applyLayout();
    // input and selection
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    viewer.setInput(as.getAlignment().getTypeCells());
    if (initialSelection != null)
        viewer.setSelection(new StructuredSelection(initialSelection));
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) ReverseCellGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.ReverseCellGraphContentProvider) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Dimension(org.eclipse.draw2d.geometry.Dimension) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

GraphLabelProvider (eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider)4 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 DefaultCell (eu.esdihumboldt.hale.common.align.model.impl.DefaultCell)2 BaseAlignmentCell (eu.esdihumboldt.hale.common.align.model.BaseAlignmentCell)1 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)1 Type (eu.esdihumboldt.hale.common.align.model.Type)1 DefaultType (eu.esdihumboldt.hale.common.align.model.impl.DefaultType)1 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 CellGraphContentProvider (eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider)1 ReverseCellGraphContentProvider (eu.esdihumboldt.hale.ui.common.graph.content.ReverseCellGraphContentProvider)1 SchemaSelection (eu.esdihumboldt.hale.ui.selection.SchemaSelection)1 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)1 OffscreenGraph (eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph)1 Dimension (java.awt.Dimension)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1