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();
}
}
});
}
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();
}
};
}
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;
}
};
}
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));
}
Aggregations