use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.
the class DiagramBaseAction method getDiagramViewer.
protected DiagramViewer getDiagramViewer() {
DiagramViewer res = editor;
final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return res;
}
final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (workbenchPage == null) {
return res;
}
IWorkbenchPart part = workbenchPage.getActivePart();
if (part instanceof DiagramViewer) {
res = (DiagramViewer) part;
} else if (part instanceof ContentOutline) {
ContentOutline co = (ContentOutline) part;
if (co.getCurrentPage() instanceof DiagramContentOutlinePage) {
DiagramContentOutlinePage dcop = (DiagramContentOutlinePage) co.getCurrentPage();
res = dcop.getEditor();
}
}
return res;
}
use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.
the class ExportImageActionTest method testAction.
public void testAction() {
final DiagramViewer editor = context.mock(DiagramViewer.class);
final SaveAsDialog saveDialog = context.mock(SaveAsDialog.class);
final GraphicalViewer graphicalViewer = context.mock(GraphicalViewer.class);
final ScalableFreeformRootEditPart scalableFreeformRootEditPart = context.mock(ScalableFreeformRootEditPart.class);
final IFigure figure = context.mock(IFigure.class);
final Control control = context.mock(Control.class);
final Display display = context.mock(Display.class);
final Rectangle rectangle = new Rectangle(0, 0, 20, 10);
// $NON-NLS-1$
final String filePath = PROJECT_NAME + File.separator + "test.jpg";
final IPath resPath = new Path(filePath);
context.checking(new Expectations() {
{
allowing(editor).getStoreFileName();
will(returnValue(filePath));
allowing(saveDialog).setOriginalName(filePath);
oneOf(saveDialog).open();
will(returnValue(0));
oneOf(saveDialog).getResult();
will(returnValue(resPath));
allowing(editor).getEditPartViewer();
will(returnValue(graphicalViewer));
allowing(graphicalViewer).getRootEditPart();
will(returnValue(scalableFreeformRootEditPart));
allowing(scalableFreeformRootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
will(returnValue(figure));
allowing(figure).getBounds();
will(returnValue(rectangle));
}
});
final ExportImageAction exportImageAction = new ExportImageAction(editor);
exportImageAction.setSaveDialog(saveDialog);
exportImageAction.setShowErrDialog(false);
exportImageAction.run();
// test is the file created
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath path = workspace.getRoot().getFullPath().append(resPath);
path = workspace.getRoot().getLocation().append(path);
File file = path.toFile();
assertTrue(file.exists() && file.isFile());
//
boolean res = file.delete();
assertTrue(res);
// GENERAL TEST:
// check for all expectations
context.assertIsSatisfied();
}
use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.
the class OpenMappingAction method run.
public void run() {
DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
DiagramViewer part = (DiagramViewer) getWorkbenchPart();
Set<Shape> selectedElements = part.getSelectedElements();
IEditorPart editorPart = null;
Iterator<Shape> iterator = selectedElements.iterator();
// open only first editor - no sense to open all of them
while (iterator.hasNext() && editorPart == null) {
Shape shape = iterator.next();
Object selection = shape.getOrmElement();
if (selection instanceof IProperty && ((IProperty) selection).getPersistentClass().isInstanceOfSpecialRootClass()) {
IProperty compositSel = ((IProperty) selection);
IProperty parentProperty = ((IPersistentClass) compositSel.getPersistentClass()).getProperty();
try {
editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, compositSel, parentProperty);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
} catch (FileNotFoundException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_canot_find_or_open_mapping_file, e);
}
continue;
}
if (selection instanceof IPersistentClass && ((IPersistentClass) selection).isInstanceOfSpecialRootClass()) {
selection = ((IPersistentClass) selection).getProperty();
}
Shape shapeParent = null;
Object selectionParent = null;
if (selection instanceof IColumn) {
shapeParent = (Shape) shape.getParent();
selectionParent = shapeParent.getOrmElement();
}
try {
editorPart = org.hibernate.eclipse.console.actions.OpenMappingAction.run(consoleConfig, selection, selectionParent);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
} catch (FileNotFoundException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenMappingAction_open_mapping_file, e);
}
}
}
use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.
the class OpenSourceAction method run.
public void run() {
DiagramEditorInput objectEditorInput = (DiagramEditorInput) ((DiagramViewer) getWorkbenchPart()).getEditorInput();
ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
DiagramViewer part = (DiagramViewer) getWorkbenchPart();
Set<Shape> selectedElements = part.getSelectedElements();
IEditorPart editorPart = null;
Iterator<Shape> iterator = selectedElements.iterator();
// open only first editor - no sense to open all of them
while (iterator.hasNext() && editorPart == null) {
Shape shape = iterator.next();
Object selection = shape.getOrmElement();
if (selection instanceof IColumn || selection instanceof ITable) {
Iterator<Connection> targetConnections = shape.getTargetConnections().iterator();
while (targetConnections.hasNext()) {
Connection connection = targetConnections.next();
Shape sh1 = connection.getSource();
Shape sh2 = connection.getTarget();
if (shape == sh1 && sh2 != null) {
shape = sh2;
break;
} else if (shape == sh2 && sh1 != null) {
shape = sh1;
break;
}
}
selection = shape.getOrmElement();
}
IPersistentClass rootClass = null;
if (selection instanceof IPersistentClass) {
rootClass = (IPersistentClass) selection;
} else if (selection instanceof IProperty) {
rootClass = ((IProperty) selection).getPersistentClass();
} else {
continue;
}
// HibernateUtils.getPersistentClassName(rootClass);
String fullyQualifiedName = rootClass.getClassName();
/*if (fullyQualifiedName.indexOf("$") > 0) {
fullyQualifiedName = fullyQualifiedName.substring(0, fullyQualifiedName.indexOf("$"));
}*/
try {
editorPart = org.hibernate.eclipse.console.actions.OpenSourceAction.run(consoleConfig, selection, fullyQualifiedName);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_open_source_file, e);
} catch (FileNotFoundException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(DiagramViewerMessages.OpenSourceAction_canot_find_source_file, e);
}
}
}
use of org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer in project jbosstools-hibernate by jbosstools.
the class PrintDiagramViewerAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
GraphicalViewer viewer;
viewer = (GraphicalViewer) getWorkbenchPart().getAdapter(GraphicalViewer.class);
PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
PrintDiagramViewerOperation op = new PrintDiagramViewerOperation(new Printer(data), viewer);
DiagramViewer dv = (DiagramViewer) getWorkbenchPart();
op.setZoom(dv.getZoom());
if (Math.abs(dv.getZoom() - dv.getFitHeightZoomValue()) < 0.00000001) {
op.setPrintMode(PrintGraphicalViewerOperation.FIT_HEIGHT);
} else if (Math.abs(dv.getZoom() - dv.getFitWidthZoomValue()) < 0.00000001) {
op.setPrintMode(PrintGraphicalViewerOperation.FIT_WIDTH);
} else if (Math.abs(dv.getZoom() - dv.getFitPageZoomValue()) < 0.00000001) {
op.setPrintMode(PrintGraphicalViewerOperation.FIT_PAGE);
} else {
op.setPrintMode(PrintGraphicalViewerOperation.TILE);
}
op.run(getWorkbenchPart().getTitle());
}
}
Aggregations