use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project gemoc-studio by eclipse.
the class AbstractTimelineView method createPartControl.
@Override
public void createPartControl(Composite parent) {
final Composite container;
if (hasDetailViewer()) {
final SashForm mainSashForm = new SashForm(parent, SWT.HORIZONTAL);
container = mainSashForm;
detailViewer = createDetailViewer(container);
} else {
container = parent;
}
timelineViewer = new ScrollingGraphicalViewer();
Composite timelineComposite = new Composite(container, SWT.NONE);
timelineComposite.setLayout(new FillLayout(SWT.HORIZONTAL | SWT.VERTICAL));
if (hasDetailViewer()) {
((SashForm) container).setWeights(new int[] { DETAIL_RATIO, TIMELINE_RATIO });
}
GridLayout layout = new GridLayout(1, false);
timelineComposite.setLayout(layout);
timelineViewer.createControl(timelineComposite);
timelineSlider = new Slider(timelineComposite, SWT.HORIZONTAL);
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
timelineSlider.setLayoutData(gridData);
gridData.grabExcessHorizontalSpace = true;
rootEditPart = new ScalableFreeformRootEditPart();
rootEditPart.setViewer(timelineViewer);
timelineViewer.setRootEditPart(rootEditPart);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
timelineViewer.getControl().setLayoutData(gridData);
timelineViewer.setEditPartFactory(getTimelineEditPartFactory());
timelineWindow = new TimelineWindow(provider);
timelineViewer.setContents(timelineWindow);
timelineSlider.setPageIncrement(timelineWindow.getLength());
timelineSlider.setThumb(timelineWindow.getLength());
timelineSlider.setSelection(timelineWindow.getStart());
if (provider != null) {
timelineSlider.setMaximum(timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
timelineSlider.setVisible(timelineWindow.getLength() < timelineWindow.getMaxTimelineIndex() + nbVirtualChoices);
} else {
timelineSlider.setVisible(false);
}
timelineSlider.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
if (follow) {
toggleFollow();
}
timelineWindow.setStart(timelineSlider.getSelection());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
if (follow) {
toggleFollow();
}
timelineWindow.setStart(timelineSlider.getSelection());
}
});
timelineWindowListener = new TimelineWindowListener();
timelineWindow.addTimelineWindowListener(timelineWindowListener);
if (provider != null) {
provider.addTimelineListener(timelineWindowListener);
}
timelineViewer.getControl().setBackground(ColorConstants.listBackground);
if (hasDetailViewer()) {
timelineViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
final ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
final Object firstElement = ((IStructuredSelection) selection).getFirstElement();
if (firstElement instanceof PossibleStepEditPart) {
final PossibleStepEditPart possibleStepEditPart = (PossibleStepEditPart) firstElement;
detailViewer.setInput(possibleStepEditPart.getModel().getPossibleStep());
}
}
}
});
}
timelineViewer.getControl().addKeyListener(new TimelineKeyListener());
final TimelineMouseListener listener = new TimelineMouseListener();
timelineViewer.getControl().addMouseListener(listener);
timelineViewer.getControl().addMouseMoveListener(listener);
timelineViewer.getControl().addMouseWheelListener(new TimelineMouseWheelListener());
rootEditPart.getZoomManager().addZoomListener(new ZoomListener() {
@Override
public void zoomChanged(double zoom) {
timelineWindow.setLength(getWindowLength());
}
});
timelineViewer.getControl().addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
timelineWindow.setLength(getWindowLength());
final Canvas canevas = (Canvas) timelineViewer.getControl();
canevas.getHorizontalBar().setVisible(false);
}
@Override
public void controlMoved(ControlEvent e) {
// nothing to do here
}
});
final ICommandService cmdService = (ICommandService) getSite().getService(ICommandService.class);
String commandID = getFollowCommandID();
if (commandID != null) {
final Command followCommand = cmdService.getCommand(commandID);
if (followCommand != null) {
final State state = followCommand.getState(RegistryToggleState.STATE_ID);
follow = state != null && ((Boolean) state.getValue()).booleanValue();
}
}
createMenuManager();
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project dbeaver by serge-rider.
the class ERDEditorPart method init.
/**
* Initializes the editor.
*/
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
rootPart = new ScalableFreeformRootEditPart();
editDomain = new DefaultEditDomain(this);
setEditDomain(editDomain);
super.init(site, input);
// add selection change listener
// getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
configPropertyListener = new ConfigPropertyListener();
ERDUIActivator.getDefault().getPreferenceStore().addPropertyChangeListener(configPropertyListener);
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project cubrid-manager by CUBRID.
the class ERSchemaEditor method createGraphicalViewer.
/**
* Creates a new <code>GraphicalViewer</code>, configures, registers and
* initializes it.
*
* @param parent the parent composite
* @return a new <code>GraphicalViewer</code>
*/
protected void createGraphicalViewer(Composite parent) {
IEditorSite editorSite = getEditorSite();
ScrollingGraphicalViewer viewer = createGraphicalViewer(editorSite, parent);
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getRootEditPart();
zoomManager = rootEditPart.getZoomManager();
zoomManager.setZoomLevels(ZOOM_LEVELS);
// hook the viewer into the EditDomain
getEditDomain().addViewer(viewer);
// acticate the viewer as selection provider for Eclipse
getSite().setSelectionProvider(viewer);
viewer.setContents(erSchema);
ContextMenuProvider provider = new SchemaContextMenuProvider(viewer, getActionRegistry());
viewer.setContextMenu(provider);
getSite().registerContextMenu(provider.getId(), provider, viewer);
graphicalViewer = viewer;
// key handler
GraphicalViewerKeyHandler graphicalViewerKeyHandler = new GraphicalViewerKeyHandler(viewer);
KeyHandler parentKeyHandler = graphicalViewerKeyHandler.setParent(getCommonKeyHandler());
viewer.setKeyHandler(parentKeyHandler);
registDropTarget();
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project cubrid-manager by CUBRID.
the class SchemaDiagramPart method getEditor.
public ERSchemaEditor getEditor() {
EditPart parentP = getParent();
if (parentP instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart parentEditor = (ScalableFreeformRootEditPart) parentP;
EditPartViewer viewer = parentEditor.getViewer();
if (viewer instanceof ValidationGraphicalViewer) {
ValidationGraphicalViewer gViewer = (ValidationGraphicalViewer) viewer;
EditDomain domain = gViewer.getEditDomain();
if (domain instanceof ERSchemaEditDomain) {
ERSchemaEditDomain erEditorDomain = (ERSchemaEditDomain) domain;
return (ERSchemaEditor) erEditorDomain.getEditorPart();
}
}
}
return null;
}
use of org.eclipse.gef.editparts.ScalableFreeformRootEditPart in project cubrid-manager by CUBRID.
the class ExportPictureTask method execute.
public void execute() {
ScalableFreeformRootEditPart rootPart = erSchemaEditor.getRootEditPart();
// To ensure every graphical element is included
IFigure figure = rootPart.getLayer(ScalableFreeformRootEditPart.PRINTABLE_LAYERS);
String suffix = filename.substring(filename.indexOf("."));
byte[] data = createImage(figure, getImageFormat(suffix));
FileOutputStream fos = null;
try {
fos = new FileOutputStream(filename);
fos.write(data);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
}
Aggregations