use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.
the class EditorPart method doSaveAs.
@Override
public void doSaveAs() {
IEntity entityContents = getComponent().getViewer().getEntityContents();
Set<IPersistenceKit> persistenceKits = new HashSet<IPersistenceKit>();
for (IPersistenceKit persistenceKit : ReflectionFactory.getPersistenceKits()) if (persistenceKit.canApply(entityContents))
persistenceKits.add(persistenceKit);
SaveAsModelDialog dialog = new SaveAsModelDialog(getSite().getWorkbenchWindow().getShell(), getContext(), persistenceKits);
if (dialog.open() == Dialog.CANCEL)
return;
IPersistenceKit persistenceKit = dialog.getPersistenceKit();
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(dialog.getResult());
try {
// perform save to new file
IFilePersistenceProvider pp = new IFilePersistenceProvider(file);
persistenceKit.writeModel(entityContents, pp);
// update default editor in package explorer
IDE.setDefaultEditor(file, ReflectionFactory.getEditorIdFromPersistenceKit(persistenceKit));
// update model input
getContext().set(IModelInput.class, new ModelInput(getContext(), pp, persistenceKit.getId()));
// update editor input
setInputWithNotify(new FileEditorInput(file));
// update editor's tab label
setPartName(file.getName());
// reset entity contents command stack and dirty state
getComponent().getViewer().setEntityContents(entityContents);
} catch (Exception e) {
E4Utils.reportError(getContext(), "Write Model errors", StringUtils.errorMessage(e), e);
}
}
use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.
the class ModelInputFunction method compute.
@Override
public Object compute(IEclipseContext context) {
final IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
bm.wDefValue("eclipse#eclipseContext", context);
final IEditorPart editorPart = context.get(IEditorPart.class);
final IEditorInput input = context.get(IEditorInput.class);
if (input instanceof IFileEditorInput) {
IFile file = ((IFileEditorInput) input).getFile();
IFilePersistenceProvider pp = new IFilePersistenceProvider(file, bm);
ModelInput modelInput = new ModelInput(context, pp, calculateBasePersistenceKitId(file));
if (editorPart != null) {
String editorId = editorPart.getSite().getId();
String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
}
return modelInput;
} else if (input instanceof IURIEditorInput) {
File file = new File(((IURIEditorInput) input).getURI());
FilePersistenceProvider pp = new FilePersistenceProvider(file, bm);
ModelInput modelInput = new ModelInput(context, pp, ReflectionFactory.getDefaultPersistenceKit().getId());
if (editorPart != null) {
String editorId = editorPart.getSite().getId();
String overridePersistenceKitId = ReflectionFactory.getPersistenceKitFromEditorId(editorId).getId();
modelInput.setOverridePersistenceKitId(overridePersistenceKitId);
}
return modelInput;
} else
return null;
}
use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.
the class AbstractE4Part method restoreState.
protected void restoreState() {
if (part.getPersistedState().containsKey("basePersistenceKitId")) {
String basePersistenceKitId = part.getPersistedState().get("basePersistenceKitId");
IModelInput modelInput = new ModelInput(context, part.getPersistedState().get("filePath"), basePersistenceKitId);
modelInput.setOverridePersistenceKitId(part.getPersistedState().get("overridePersistenceKitId"));
updateModelInput(modelInput);
}
}
use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.
the class RevertHandler method execute.
@Execute
public void execute(EPartService partService, IModelInput modelInput, @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
if (E4Utils.isLegacyApplication()) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
viewer.setContents((IModelInput) bm.wGetValue("modelInput"), null);
} else {
AbstractE4Part part = (AbstractE4Part) partService.getActivePart().getObject();
part.getViewer().setContents(modelInput, null);
}
}
use of org.whole.lang.e4.ui.input.ModelInput in project whole by wholeplatform.
the class AbstractE4Part method createPartControl.
@PostConstruct
public void createPartControl(Composite parent) {
restoreState();
registerHandlers();
parent.setLayout(new FillLayout());
viewer = createEntityViewer(parent);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateSelection(E4Utils.createSelectionBindings(event, context));
}
});
viewer.getControl().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent event) {
}
@Override
@SuppressWarnings("unchecked")
public void focusGained(FocusEvent event) {
context.set(IEntityPartViewer.class, viewer);
context.set(ActionRegistry.class, actionRegistry);
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
}
});
viewer.addPartFocusListener(new IPartFocusListener() {
@SuppressWarnings("unchecked")
public void focusChanged(IEntityPart oldPart, IEntityPart newPart) {
updateSelection(E4Utils.createSelectionBindings(viewer.getSelectedEditParts(), viewer, context));
}
});
E4KeyHandler keyHandler = new E4KeyHandler(context);
keyHandler.setParent(new E4NavigationKeyHandler(context));
context.set(IEntityPartViewer.class, viewer);
viewer.setKeyHandler(keyHandler);
viewer.setContents(modelInput, createDefaultContents());
actionRegistry = ContextInjectionFactory.make(ActionRegistry.class, context);
actionRegistry.registerKeyActions(viewer.getKeyHandler());
context.set(ActionRegistry.class, actionRegistry);
configureContextMenu();
if (!E4Utils.isLegacyApplication())
viewer.getCommandStack().addCommandStackEventListener(new CommandStackEventListener() {
@Override
public void stackChanged(CommandStackEvent event) {
if ((event.getDetail() & CommandStack.POST_MASK) != 0)
part.setDirty(viewer.isDirty());
}
});
reloader = new LazyConfirmationDialogReloader(viewer.getControl(), new Runnable() {
@Override
public void run() {
viewer.setContents(modelInput, null);
}
});
}
Aggregations