Search in sources :

Example 1 with Logger

use of org.eclipse.e4.core.services.log.Logger in project eclipse.platform.ui by eclipse-platform.

the class HandlerServiceImpl method executeHandler.

@Override
public Object executeHandler(ParameterizedCommand command) {
    final IEclipseContext staticContext = EclipseContextFactory.create(TMP_STATIC_CONTEXT);
    try {
        return executeHandler(command, staticContext);
    } finally {
        Object obj = staticContext.get(HandlerServiceImpl.HANDLER_EXCEPTION);
        if (obj instanceof ExecutionException) {
            if (logger != null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                logger.error((Throwable) obj, "Command '" + command.getId() + "' failed");
            }
        }
        staticContext.dispose();
    }
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 2 with Logger

use of org.eclipse.e4.core.services.log.Logger in project eclipse.platform.ui by eclipse-platform.

the class ResourceHandler method loadMostRecentModel.

@Override
public Resource loadMostRecentModel() {
    File workbenchData = null;
    URI restoreLocation = null;
    if (saveAndRestore) {
        workbenchData = getWorkbenchSaveLocation();
        restoreLocation = URI.createFileURI(workbenchData.getAbsolutePath());
    }
    if (clearPersistedState && workbenchData != null && workbenchData.exists()) {
        workbenchData.delete();
    }
    // last stored time-stamp
    long restoreLastModified = restoreLocation == null ? 0L : new File(restoreLocation.toFileString()).lastModified();
    // See bug 380663, bug 381219
    // long lastApplicationModification = getLastApplicationModification();
    // boolean restore = restoreLastModified > lastApplicationModification;
    boolean restore = restoreLastModified > 0;
    boolean initialModel;
    resource = null;
    if (restore && saveAndRestore) {
        resource = loadResource(restoreLocation);
        // immediately, so throw out the persisted state and reinitialize with the defaults.
        if (!hasTopLevelWindows(resource)) {
            if (logger != null) {
                // log a stack trace to help debug the corruption
                logger.error(// log a stack trace to help debug the corruption
                new Exception(), // $NON-NLS-1$
                "The persisted application model has no top-level window. Reinitializing with the default application model.");
            }
            resource = null;
        }
    }
    if (resource == null) {
        Resource applicationResource = loadResource(applicationDefinitionInstance);
        MApplication theApp = (MApplication) applicationResource.getContents().get(0);
        resource = createResourceWithApp(theApp);
        context.set(E4Workbench.NO_SAVED_MODEL_FOUND, Boolean.TRUE);
        initialModel = true;
    } else {
        initialModel = false;
    }
    // Add model items described in the model extension point
    // This has to be done before commands are put into the context
    MApplication appElement = (MApplication) resource.getContents().get(0);
    this.context.set(MApplication.class, appElement);
    ModelAssembler mac = context.get(ModelAssembler.class);
    if (mac != null) {
        ContextInjectionFactory.invoke(mac, PostConstruct.class, context);
        mac.processModel(initialModel);
    }
    if (!hasTopLevelWindows(resource) && logger != null) {
        // log a stack trace to help debug the
        logger.error(// log a stack trace to help debug the
        new Exception(), // corruption
        // $NON-NLS-1$
        "Loading the application model results in no top-level window." + // $NON-NLS-1$
        "Continuing execution, but the missing window may cause other initialization failures.");
    }
    CommandLineOptionModelProcessor processor = ContextInjectionFactory.make(CommandLineOptionModelProcessor.class, context);
    processor.process();
    return resource;
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) File(java.io.File) URI(org.eclipse.emf.common.util.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) MApplication(org.eclipse.e4.ui.model.application.MApplication)

Example 3 with Logger

use of org.eclipse.e4.core.services.log.Logger in project eclipse.platform.ui by eclipse-platform.

the class DefaultLoggerProvider method getClassLogger.

@Override
public Logger getClassLogger(Class<?> clazz) {
    IEclipseContext childContext = context.createChild();
    // $NON-NLS-1$
    childContext.set("logger.bundlename", FrameworkUtil.getBundle(clazz).getSymbolicName());
    return ContextInjectionFactory.make(WorkbenchLogger.class, childContext);
}
Also used : IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 4 with Logger

use of org.eclipse.e4.core.services.log.Logger in project eclipse.platform.ui by eclipse-platform.

the class E4Workbench method instantiateRenderer.

/**
 */
public void instantiateRenderer() {
    renderer = appContext.get(IPresentationEngine.class);
    if (renderer == null) {
        String presentationURI = (String) appContext.get(IWorkbench.PRESENTATION_URI_ARG);
        if (presentationURI != null) {
            IContributionFactory factory = appContext.get(IContributionFactory.class);
            renderer = (IPresentationEngine) factory.create(presentationURI, appContext);
            appContext.set(IPresentationEngine.class, renderer);
        }
        if (renderer == null) {
            Logger logger = appContext.get(Logger.class);
            // $NON-NLS-1$
            logger.error("Failed to create the presentation engine for URI: " + presentationURI);
        }
    }
}
Also used : Logger(org.eclipse.e4.core.services.log.Logger) IPresentationEngine(org.eclipse.e4.ui.workbench.IPresentationEngine) IContributionFactory(org.eclipse.e4.core.services.contributions.IContributionFactory)

Example 5 with Logger

use of org.eclipse.e4.core.services.log.Logger in project eclipse.platform.ui by eclipse-platform.

the class WBWRenderer method createWidget.

@Override
public Object createWidget(MUIElement element, Object parent) {
    final Widget newWidget;
    if (!(element instanceof MWindow) || (parent != null && !(parent instanceof Control))) {
        return null;
    }
    MWindow wbwModel = (MWindow) element;
    MApplication appModel = wbwModel.getContext().get(MApplication.class);
    Boolean rtlMode = (Boolean) appModel.getTransientData().get(E4Workbench.RTL_MODE);
    int rtlStyle = (rtlMode != null && rtlMode.booleanValue()) ? SWT.RIGHT_TO_LEFT : 0;
    Shell parentShell = parent == null ? null : ((Control) parent).getShell();
    final Shell wbwShell;
    int styleOverride = getStyleOverride(wbwModel) | rtlStyle;
    if (parentShell == null) {
        int style = styleOverride == -1 ? SWT.SHELL_TRIM | rtlStyle : styleOverride;
        wbwShell = new Shell(display, style);
        // $NON-NLS-1$
        wbwModel.getTags().add("topLevel");
    } else {
        int style = SWT.TITLE | SWT.RESIZE | SWT.MAX | SWT.CLOSE | rtlStyle;
        style = styleOverride == -1 ? style : styleOverride;
        if (wbwModel.getTags().contains(IPresentationEngine.WINDOW_TOP_LEVEL)) {
            wbwShell = new Shell(display, style);
        } else {
            wbwShell = new Shell(parentShell, style);
        }
        // Prevent ESC from closing the DW
        wbwShell.addTraverseListener(e -> {
            if (e.detail == SWT.TRAVERSE_ESCAPE) {
                e.doit = false;
            }
        });
    }
    wbwShell.setBackgroundMode(SWT.INHERIT_DEFAULT);
    Rectangle modelBounds = wbwShell.getBounds();
    if (wbwModel.isSetX()) {
        modelBounds.x = wbwModel.getX();
    }
    if (wbwModel.isSetY()) {
        modelBounds.y = wbwModel.getY();
    }
    if (wbwModel.isSetHeight()) {
        modelBounds.height = wbwModel.getHeight();
    }
    if (wbwModel.isSetWidth()) {
        modelBounds.width = wbwModel.getWidth();
    }
    // Force the shell onto the display if it would be invisible otherwise
    Display display = Display.getCurrent();
    Monitor closestMonitor = Util.getClosestMonitor(display, Geometry.centerPoint(modelBounds));
    Rectangle displayBounds = closestMonitor.getClientArea();
    if (!modelBounds.intersects(displayBounds)) {
        Geometry.moveInside(modelBounds, displayBounds);
    }
    wbwShell.setBounds(modelBounds);
    setCSSInfo(wbwModel, wbwShell);
    // set up context
    IEclipseContext localContext = getContext(wbwModel);
    // We need to retrieve specific CSS properties for our layout.
    CSSEngineHelper helper = new CSSEngineHelper(localContext, wbwShell);
    TrimmedPartLayout tl = new TrimmedPartLayout(wbwShell);
    tl.gutterTop = helper.getMarginTop(0);
    tl.gutterBottom = helper.getMarginBottom(0);
    tl.gutterLeft = helper.getMarginLeft(0);
    tl.gutterRight = helper.getMarginRight(0);
    wbwShell.setLayout(tl);
    newWidget = wbwShell;
    bindWidget(element, newWidget);
    // Add the shell into the WBW's context
    localContext.set(Shell.class, wbwShell);
    localContext.set(E4Workbench.LOCAL_ACTIVE_SHELL, wbwShell);
    setCloseHandler(wbwModel);
    localContext.set(IShellProvider.class, () -> wbwShell);
    final PartServiceSaveHandler saveHandler = new PartServiceSaveHandler() {

        @Override
        public Save promptToSave(MPart dirtyPart) {
            Shell shell = (Shell) context.get(IServiceConstants.ACTIVE_SHELL);
            Object[] elements = promptForSave(shell, Collections.singleton(dirtyPart));
            if (elements == null) {
                return Save.CANCEL;
            }
            return elements.length == 0 ? Save.NO : Save.YES;
        }

        @Override
        public Save[] promptToSave(Collection<MPart> dirtyParts) {
            List<MPart> parts = new ArrayList<>(dirtyParts);
            Shell shell = (Shell) context.get(IServiceConstants.ACTIVE_SHELL);
            Save[] response = new Save[dirtyParts.size()];
            Object[] elements = promptForSave(shell, parts);
            if (elements == null) {
                Arrays.fill(response, Save.CANCEL);
            } else {
                Arrays.fill(response, Save.NO);
                for (Object element : elements) {
                    response[parts.indexOf(element)] = Save.YES;
                }
            }
            return response;
        }
    };
    saveHandler.logger = logger;
    localContext.set(ISaveHandler.class, saveHandler);
    if (wbwModel.getLabel() != null) {
        wbwShell.setText(wbwModel.getLocalizedLabel());
    }
    Image windowImage = getImage(wbwModel);
    if (windowImage != null) {
        wbwShell.setImage(windowImage);
    } else {
        // TODO: This should be added to the model, see bug 308494
        // it allows for a range of icon sizes that the platform gets to
        // choose from
        wbwShell.setImages(Window.getDefaultImages());
    }
    return newWidget;
}
Also used : MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) Widget(org.eclipse.swt.widgets.Widget) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) MWindow(org.eclipse.e4.ui.model.application.ui.basic.MWindow) PartServiceSaveHandler(org.eclipse.e4.ui.internal.workbench.PartServiceSaveHandler) Control(org.eclipse.swt.widgets.Control) Shell(org.eclipse.swt.widgets.Shell) Monitor(org.eclipse.swt.widgets.Monitor) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Collection(java.util.Collection) MApplication(org.eclipse.e4.ui.model.application.MApplication) Display(org.eclipse.swt.widgets.Display)

Aggregations

IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)12 IOException (java.io.IOException)9 Logger (org.eclipse.e4.core.services.log.Logger)7 EObject (org.eclipse.emf.ecore.EObject)7 ArrayList (java.util.ArrayList)6 InjectionException (org.eclipse.e4.core.di.InjectionException)5 MApplication (org.eclipse.e4.ui.model.application.MApplication)5 MWindow (org.eclipse.e4.ui.model.application.ui.basic.MWindow)5 List (java.util.List)4 IPresentationEngine (org.eclipse.e4.ui.workbench.IPresentationEngine)4 Display (org.eclipse.swt.widgets.Display)4 Shell (org.eclipse.swt.widgets.Shell)4 File (java.io.File)3 Set (java.util.Set)3 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)3 Platform (org.eclipse.core.runtime.Platform)3 ContextInjectionFactory (org.eclipse.e4.core.contexts.ContextInjectionFactory)3 IContributionFactory (org.eclipse.e4.core.services.contributions.IContributionFactory)3 E4Workbench (org.eclipse.e4.ui.internal.workbench.E4Workbench)3 MContribution (org.eclipse.e4.ui.model.application.MContribution)3