use of org.eclipse.e4.ui.model.application.MApplication in project portfolio by buchen.
the class NewFileHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, //
@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MApplication app, EPartService partService, EModelService modelService) {
NewClientWizard wizard = new NewClientWizard();
WizardDialog dialog = new WizardDialog(shell, wizard);
if (dialog.open() == Window.OK) {
MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
part.setLabel(Messages.LabelUnnamedXml);
part.getTransientData().put(Client.class.getName(), wizard.getClient());
if (activePart != null)
activePart.getParent().getChildren().add(part);
else
((MPartStack) modelService.find(UIConstants.PartStack.MAIN, app)).getChildren().add(part);
part.setVisible(true);
part.getParent().setVisible(true);
partService.showPart(part, PartState.ACTIVATE);
}
}
use of org.eclipse.e4.ui.model.application.MApplication in project portfolio by buchen.
the class OpenRecentFileHandler method execute.
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, //
@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MApplication app, EPartService partService, EModelService modelService, @Named("name.abuchen.portfolio.ui.param.file") String file) {
MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
part.setLabel(new File(file).getName());
part.setTooltip(file);
part.getPersistedState().put(UIConstants.File.PERSISTED_STATE_KEY, file);
if (activePart != null)
activePart.getParent().getChildren().add(part);
else
((MPartStack) modelService.find(UIConstants.PartStack.MAIN, app)).getChildren().add(part);
part.setVisible(true);
part.getParent().setVisible(true);
partService.showPart(part, PartState.ACTIVATE);
}
use of org.eclipse.e4.ui.model.application.MApplication in project portfolio by buchen.
the class OpenSampleHandler method execute.
@Execute
public void execute(//
@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, //
final MApplication app, final EPartService partService, final EModelService modelService, @Named(UIConstants.Parameter.SAMPLE_FILE) final String sampleFile) {
try {
IRunnableWithProgress loadResourceOperation = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try (InputStream in = this.getClass().getResourceAsStream(sampleFile)) {
InputStream inputStream = new ProgressMonitorInputStream(in, monitor);
Reader replacingReader = new TokenReplacingReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8), buildResourcesTokenResolver());
final Client client = ClientFactory.load(replacingReader);
fixTaxonomyLabels(client);
sync.asyncExec(() -> {
MPart part = partService.createPart(UIConstants.Part.PORTFOLIO);
part.setLabel(sampleFile.substring(sampleFile.lastIndexOf('/') + 1));
part.getTransientData().put(Client.class.getName(), client);
MPartStack stack = (MPartStack) modelService.find(UIConstants.PartStack.MAIN, app);
stack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
});
} catch (IOException ignore) {
PortfolioPlugin.log(ignore);
}
}
};
new ProgressMonitorDialog(shell).run(true, true, loadResourceOperation);
} catch (InvocationTargetException | InterruptedException e) {
PortfolioPlugin.log(e);
}
}
use of org.eclipse.e4.ui.model.application.MApplication in project yamcs-studio by yamcs.
the class OPIView method findPlaceholder.
/**
* Find the MPlaceholder corresponding to this MPart in the MPerspective. This may have persisted information
* relevant to loading this OPIView.
*
* @return corresponding placeholder
*/
private MPlaceholder findPlaceholder() {
// do not remove casting - RAP 3.0 still needs it
final IEclipseContext localContext = (IEclipseContext) getViewSite().getService(IEclipseContext.class);
final MPart part = localContext.get(MPart.class);
final EModelService service = (EModelService) PlatformUI.getWorkbench().getService(EModelService.class);
final IEclipseContext globalContext = (IEclipseContext) PlatformUI.getWorkbench().getService(IEclipseContext.class);
final MApplication app = globalContext.get(MApplication.class);
final List<MPlaceholder> phs = service.findElements(app, null, MPlaceholder.class, null);
for (MPlaceholder ph : phs) {
if (ph.getRef() == part) {
return ph;
}
}
return null;
}
use of org.eclipse.e4.ui.model.application.MApplication in project whole by wholeplatform.
the class E4Utils method findMenu.
@SuppressWarnings("unchecked")
public static <T> T findMenu(String elementId, EModelService modelService, MApplication application, Class<T> type) {
for (MWindow window : modelService.findElements(application, null, MWindow.class, null)) {
MMenu mainMenu = window.getMainMenu();
if (mainMenu == null)
continue;
MMenuElement menuElement = findMenu(elementId, mainMenu);
if (menuElement != null)
return (T) menuElement;
}
return null;
}
Aggregations