use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class PNGImageFileTransferDragSourceListener method createFile.
protected File createFile(IEntityPart entityPart) throws Exception {
Image image = WholeNonResizableEditPolicy.createFeedbackImage((IGraphicalEntityPart) entityPart, 255, false, FitToMemoryStrategy.instance());
ImageData imageData = image.getImageData();
String fileName = ClipboardUtils.DEFAULT_OUTPUT_FILENAME;
if (getViewer() instanceof IEntityPartViewer) {
IBindingManager bm = ((IEntityPartViewer) getViewer()).getContextBindings();
if (bm.wIsSet("fileName"))
fileName = bm.wStringValue("fileName");
}
File file = ClipboardUtils.createTempImageFile(fileName, imageData, ClipboardUtils.DEFAULT_OUTPUT_DPI);
image.dispose();
return file;
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class EditorPart method createPartControl.
@Override
public void createPartControl(Composite parent) {
IImportAsModelDialogFactory factory = ContextInjectionFactory.make(ImportAsModelDialogFactory.class, getContext());
getContext().set(IImportAsModelDialogFactory.class, factory);
super.createPartControl(parent);
getContext().get(MPart.class).setElementId("org.eclipse.e4.ui.compatibility.editor");
setPartName(getEditorInput().getName());
final IEntityPartViewer viewer = getComponent().getViewer();
viewer.getCommandStack().addCommandStackEventListener(listener = new CommandStackEventListener() {
@Override
public void stackChanged(CommandStackEvent event) {
if ((event.getDetail() & CommandStack.POST_MASK) != 0)
setDirtyState(viewer.isDirty());
}
});
undoAction = new UndoAction(getContext(), UNDO_LABEL);
undoAction.update();
redoAction = new RedoAction(getContext(), REDO_LABEL);
redoAction.update();
if (getEditorInput() instanceof IFileEditorInput) {
IWorkspace workspace = ((IFileEditorInput) getEditorInput()).getFile().getWorkspace();
workspace.addResourceChangeListener(resourceListener = new ResourceChangeListener());
}
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class ReplaceWithResourceAction method run.
@Override
public void run() {
ESelectionService selectionService = getContext().get(ESelectionService.class);
IBindingManager bm = (IBindingManager) selectionService.getSelection();
IEntity focusEntity = bm.wGet("focusEntity");
ResourceKind resourceKind = getResourceKind(focusEntity);
Shell shell = (Shell) getContext().get(IServiceConstants.ACTIVE_SHELL);
boolean selectionPerformed = false;
switch(resourceKind) {
case WORKSPACE:
selectionPerformed = performWorkspaceResourceSelection(shell, focusEntity);
break;
case CLASSPATH:
selectionPerformed = performClasspathResourceSelection(shell, focusEntity);
break;
case FILE_SYSTEM:
case URL:
selectionPerformed = performFilesystemSelection(shell, focusEntity, resourceKind == ResourceKind.URL);
break;
}
if (!selectionPerformed)
return;
IEntity replacement = GenericEntityFactory.instance.create(ed, path);
ModelTransactionCommand mtc = new ModelTransactionCommand(focusEntity);
try {
mtc.setLabel("replace with class name");
mtc.begin();
performReplace(focusEntity, replacement);
mtc.commit();
if (mtc.canUndo()) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
commandStack.execute(mtc);
}
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
}
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class AbstractLinkableSelectionListener method isRelevant.
protected boolean isRelevant(Object selection) {
if (!(selection instanceof IBindingManager))
return false;
IBindingManager actualSelection = (IBindingManager) selection;
IEntityPartViewer selectedViewer = (IEntityPartViewer) actualSelection.wGetValue("viewer");
if (viewer == selectedViewer)
return false;
lastSelection = actualSelection.clone();
return linkType.isLinkedToActivePart() || (linkType.isLinkedToFixedPart() && selectedViewer == linkedViewer);
}
use of org.whole.lang.ui.viewers.IEntityPartViewer in project whole by wholeplatform.
the class E4FindReplaceDialog method doReplaceAll.
protected void doReplaceAll() {
IEntity self = selection.wGet("self");
iterator.reset(self);
if (!findNext(true))
return;
boolean state = enableSelectionTracking(false);
IEntity replacement = replaceViewer.getEntityContents();
IEntity lastReplaced = null;
ModelTransactionCommand command = new ModelTransactionCommand();
command.setModel(getFoundEntity());
try {
command.begin();
do {
lastReplaced = EntityUtils.clone(replacement);
Matcher.substitute(lastReplaced, bindings, false);
iterator.set(lastReplaced);
} while (findNext(true));
command.commit();
} catch (Exception e) {
command.rollbackIfNeeded();
} finally {
clearFoundEntity();
}
IEntityPartViewer viewer = (IEntityPartViewer) selection.wGetValue("viewer");
viewer.getCommandStack().execute(command);
Control control = viewer.getControl();
if (lastReplaced != null) {
final IEntity revealEntity = lastReplaced;
control.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
boolean state = enableSelectionTracking(false);
selectAndReveal(revealEntity);
enableSelectionTracking(state);
}
});
}
enableSelectionTracking(state);
}
Aggregations