Search in sources :

Example 6 with EModelService

use of org.eclipse.e4.ui.workbench.modeling.EModelService 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);
    }
}
Also used : ProgressMonitorInputStream(name.abuchen.portfolio.util.ProgressMonitorInputStream) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) InputStreamReader(java.io.InputStreamReader) MPartStack(org.eclipse.e4.ui.model.application.ui.basic.MPartStack) ProgressMonitorInputStream(name.abuchen.portfolio.util.ProgressMonitorInputStream) InputStream(java.io.InputStream) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) TokenReplacingReader(name.abuchen.portfolio.util.TokenReplacingReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TokenReplacingReader(name.abuchen.portfolio.util.TokenReplacingReader) Client(name.abuchen.portfolio.model.Client) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 7 with EModelService

use of org.eclipse.e4.ui.workbench.modeling.EModelService in project linuxtools by eclipse.

the class ImageBuildPage method createControl.

@Override
public void createControl(Composite parent) {
    final Composite container = new Composite(parent, SWT.NULL);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    container.setLayout(layout);
    Label label = new Label(container, SWT.NULL);
    Label nameLabel = new Label(container, SWT.NULL);
    nameLabel.setText(WizardMessages.getString(NAME_LABEL));
    nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
    nameText.addModifyListener(Listener);
    nameText.setToolTipText(WizardMessages.getString(NAME_TOOLTIP));
    Label dirLabel = new Label(container, SWT.NULL);
    dirLabel.setText(WizardMessages.getString(DIRECTORY_LABEL));
    directoryText = new Text(container, SWT.BORDER | SWT.SINGLE);
    directoryText.addModifyListener(Listener);
    directoryText.setToolTipText(WizardMessages.getString(DIRECTORY_TOOLTIP));
    Button browse = new Button(container, SWT.NULL);
    browse.setText(WizardMessages.getString(BROWSE_LABEL));
    browse.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        DirectoryDialog d = new DirectoryDialog(container.getShell());
        String k = d.open();
        if (k != null)
            directoryText.setText(k);
    }));
    editButton = new Button(container, SWT.NULL);
    editButton.setText(WizardMessages.getString(EDIT_LABEL));
    editButton.setEnabled(false);
    editButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        String dir = directoryText.getText();
        IFileStore fileStore = EFS.getLocalFileSystem().getStore(// $NON-NLS-1$
        new Path(dir).append("Dockerfile"));
        // $NON-NLS-1$
        java.nio.file.Path filePath = Paths.get(dir, "Dockerfile");
        if (!Files.exists(filePath)) {
            try {
                Files.createFile(filePath);
            } catch (IOException e1) {
            // File won't exist, and directory should be
            // writable
            }
        }
        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        try {
            IEditorPart dockerFileEditor = IDE.openEditorOnFileStore(page, fileStore);
            IWorkbenchPartSite site = page.getActivePart().getSite();
            EModelService s = site.getService(EModelService.class);
            MPartSashContainerElement p = site.getService(MPart.class);
            s.detach(p, 100, 100, 500, 375);
            dockerFileEditor.getEditorSite().getShell().setText(WizardMessages.getString(// $NON-NLS-1$
            "ImageBuild.editor.name"));
            editors.add(dockerFileEditor);
        } catch (PartInitException e1) {
            Activator.log(e1);
        }
        validate();
    }));
    Point p1 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point p2 = directoryText.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Point p3 = browse.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int centering = (p2.y - p1.y + 1) / 2;
    int centering2 = (p3.y - p2.y + 1) / 2;
    FormData f = new FormData();
    f.top = new FormAttachment(0);
    label.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(label, 11 + centering + centering2);
    f.left = new FormAttachment(0, 0);
    nameLabel.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(label, 11 + centering2);
    f.left = new FormAttachment(nameLabel, 5);
    f.right = new FormAttachment(browse, -10);
    nameText.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11 + centering + centering2);
    f.left = new FormAttachment(0, 0);
    dirLabel.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11);
    f.right = new FormAttachment(100);
    editButton.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11);
    f.right = new FormAttachment(editButton, -10);
    browse.setLayoutData(f);
    f = new FormData();
    f.top = new FormAttachment(nameLabel, 11 + centering2);
    f.left = new FormAttachment(nameLabel, 5);
    f.right = new FormAttachment(browse, -10);
    directoryText.setLayoutData(f);
    if (lastDirectoryPath != null) {
        directoryText.setText(lastDirectoryPath);
    }
    setControl(container);
    setPageComplete(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) IDE(org.eclipse.ui.ide.IDE) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Activator(org.eclipse.linuxtools.docker.ui.Activator) Point(org.eclipse.swt.graphics.Point) HashSet(java.util.HashSet) IMessageProvider(org.eclipse.jface.dialogs.IMessageProvider) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) WizardPage(org.eclipse.jface.wizard.WizardPage) EFS(org.eclipse.core.filesystem.EFS) IEditorPart(org.eclipse.ui.IEditorPart) IFileStore(org.eclipse.core.filesystem.IFileStore) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) Files(java.nio.file.Files) FormLayout(org.eclipse.swt.layout.FormLayout) PlatformUI(org.eclipse.ui.PlatformUI) IFileInfo(org.eclipse.core.filesystem.IFileInfo) FormData(org.eclipse.swt.layout.FormData) MPartSashContainerElement(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement) Set(java.util.Set) IOException(java.io.IOException) FormAttachment(org.eclipse.swt.layout.FormAttachment) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) Paths(java.nio.file.Paths) ModifyListener(org.eclipse.swt.events.ModifyListener) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Label(org.eclipse.swt.widgets.Label) SelectionListener(org.eclipse.swt.events.SelectionListener) Path(org.eclipse.core.runtime.Path) FormData(org.eclipse.swt.layout.FormData) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Composite(org.eclipse.swt.widgets.Composite) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Button(org.eclipse.swt.widgets.Button) MPartSashContainerElement(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) FormAttachment(org.eclipse.swt.layout.FormAttachment) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 8 with EModelService

use of org.eclipse.e4.ui.workbench.modeling.EModelService in project yamcs-studio by yamcs.

the class UIHelper method detachView.

/**
 * @param view
 *            View to 'detach'
 */
public void detachView(IViewPart view) {
    // TODO Use more generic IWorkbenchPart?, getPartSite()?
    // Pre-E4 code:
    // ((WorkbenchPage)page).detachView(page.findViewReference(OPIView.ID, secondID));
    // See http://tomsondev.bestsolution.at/2012/07/13/so-you-used-internal-api/
    final EModelService model = view.getSite().getService(EModelService.class);
    MPartSashContainerElement p = view.getSite().getService(MPart.class);
    // Part may be shared by several perspectives, get the shared instance
    if (p.getCurSharedRef() != null)
        p = p.getCurSharedRef();
    model.detach(p, 100, 100, 600, 800);
}
Also used : EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) MPartSashContainerElement(org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement)

Example 9 with EModelService

use of org.eclipse.e4.ui.workbench.modeling.EModelService 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;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) EModelService(org.eclipse.e4.ui.workbench.modeling.EModelService) MPlaceholder(org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 10 with EModelService

use of org.eclipse.e4.ui.workbench.modeling.EModelService 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;
}
Also used : MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) MMenu(org.eclipse.e4.ui.model.application.ui.menu.MMenu) MMenuElement(org.eclipse.e4.ui.model.application.ui.menu.MMenuElement)

Aggregations

MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)10 Execute (org.eclipse.e4.core.di.annotations.Execute)5 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)5 EModelService (org.eclipse.e4.ui.workbench.modeling.EModelService)4 File (java.io.File)3 IOException (java.io.IOException)2 Client (name.abuchen.portfolio.model.Client)2 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)2 MApplication (org.eclipse.e4.ui.model.application.MApplication)2 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)2 MPlaceholder (org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder)2 MPartSashContainerElement (org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainerElement)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1