Search in sources :

Example 16 with Logger

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

the class ModelUtils method merge.

public static List<MApplicationElement> merge(MApplicationElement container, EStructuralFeature feature, List<MApplicationElement> elements, String positionInList) {
    EObject eContainer = (EObject) container;
    if (feature.isMany()) {
        List<MApplicationElement> copy = new ArrayList<>(elements);
        @SuppressWarnings("unchecked") List<MApplicationElement> list = (List<MApplicationElement>) eContainer.eGet(feature);
        boolean flag = true;
        if (positionInList != null && positionInList.trim().length() != 0) {
            int index = -1;
            PositionInfo posInfo = PositionInfo.parse(positionInList);
            if (posInfo != null) {
                switch(posInfo.getPosition()) {
                    case FIRST:
                        index = 0;
                        break;
                    case INDEX:
                        index = posInfo.getPositionReferenceAsInteger();
                        break;
                    case BEFORE:
                    case AFTER:
                        int tmpIndex = -1;
                        String elementId = posInfo.getPositionReference();
                        for (int i = 0; i < list.size(); i++) {
                            if (elementId.equals((list.get(i)).getElementId())) {
                                tmpIndex = i;
                                break;
                            }
                        }
                        if (tmpIndex != -1) {
                            if (posInfo.getPosition() == Position.BEFORE) {
                                index = tmpIndex;
                            } else {
                                index = tmpIndex + 1;
                            }
                        } else {
                            Platform.getLog(ModelUtils.class).warn(MessageFormat.format("Could not find element with Id ''{0}'' in ''{1}''", elementId, container.getElementId()));
                        }
                    case LAST:
                    default:
                        // position
                        break;
                }
            } else {
                invalidPrefixWarning(container, positionInList);
            }
            if (index >= 0 && list.size() > index) {
                flag = false;
                mergeList(list, elements, index);
            }
        }
        // If there was no match append it to the list
        if (flag) {
            mergeList(list, elements, -1);
        }
        return copy;
    } else if (elements.size() >= 1) {
        if (elements.size() > 1) {
            // FIXME Pass the logger
            System.err.println("The feature is single valued but a list of values is passed in.");
        }
        MApplicationElement e = elements.get(0);
        eContainer.eSet(feature, e);
        return Collections.singletonList(e);
    }
    return Collections.emptyList();
}
Also used : MApplicationElement(org.eclipse.e4.ui.model.application.MApplicationElement) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with Logger

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

the class HandledContributionItem method executeItem.

@Override
protected void executeItem(Event trigger) {
    ParameterizedCommand cmd = getModel().getWbCommand();
    if (cmd == null) {
        return;
    }
    final IEclipseContext lclContext = getContext(getModel());
    EHandlerService service = lclContext.get(EHandlerService.class);
    final IEclipseContext staticContext = getStaticContext(trigger);
    service.executeHandler(cmd, staticContext);
    Object object = staticContext.get(HandlerServiceImpl.HANDLER_EXCEPTION);
    if (object instanceof ExecutionException) {
        if (logger != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            logger.error((Throwable) object, "Command '" + cmd.getId() + "' failed");
        }
    }
}
Also used : EHandlerService(org.eclipse.e4.core.commands.EHandlerService) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ExecutionException(org.eclipse.core.commands.ExecutionException) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 18 with Logger

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

the class SWTPartRenderer method disposeWidget.

@Override
public void disposeWidget(MUIElement element) {
    disposeAdornedImage(element);
    if (element.getWidget() instanceof Widget) {
        Widget curWidget = (Widget) element.getWidget();
        if (curWidget != null && !curWidget.isDisposed()) {
            unbindWidget(element);
            try {
                curWidget.dispose();
            } catch (Exception e) {
                Logger logService = context.get(Logger.class);
                if (logService != null) {
                    // $NON-NLS-1$
                    String msg = "Error disposing widget for : " + element.getClass().getName();
                    if (element instanceof MUILabel) {
                        msg += ' ' + ((MUILabel) element).getLocalizedLabel();
                    }
                    logService.error(e, msg);
                }
            }
        }
    }
    element.setWidget(null);
}
Also used : Widget(org.eclipse.swt.widgets.Widget) MUILabel(org.eclipse.e4.ui.model.application.ui.MUILabel) Logger(org.eclipse.e4.core.services.log.Logger)

Example 19 with Logger

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

the class E4Application method saveModel.

public void saveModel() {
    // Save the model into the targetURI
    if (lcManager != null && workbench != null) {
        ContextInjectionFactory.invoke(lcManager, PreSave.class, workbench.getContext(), null);
    }
    try {
        if (!(handler instanceof ResourceHandler) || ((ResourceHandler) handler).hasTopLevelWindows()) {
            handler.save();
        } else {
            Logger logger = new WorkbenchLogger(PLUGIN_ID);
            // log a stack trace for debugging
            logger.error(// log a stack trace for debugging
            new Exception(), // $NON-NLS-1$
            "Attempted to save a workbench model that had no top-level windows! " + // $NON-NLS-1$
            "Skipped saving the model to avoid corruption.");
        }
    } catch (IOException e) {
        Logger logger = new WorkbenchLogger(PLUGIN_ID);
        // $NON-NLS-1$
        logger.error(e, "Error saving the workbench model");
    }
}
Also used : WorkbenchLogger(org.eclipse.e4.ui.internal.workbench.WorkbenchLogger) ResourceHandler(org.eclipse.e4.ui.internal.workbench.ResourceHandler) IModelResourceHandler(org.eclipse.e4.ui.workbench.IModelResourceHandler) IOException(java.io.IOException) Logger(org.eclipse.e4.core.services.log.Logger) WorkbenchLogger(org.eclipse.e4.ui.internal.workbench.WorkbenchLogger) IOException(java.io.IOException)

Example 20 with Logger

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

the class PartRenderingEngine method createGui.

@Override
public Object createGui(final MUIElement element, final Object parentWidget, final IEclipseContext parentContext) {
    final Object[] gui = { null };
    // wrap the handling in a SafeRunner so that exceptions do not prevent
    // the renderer from processing other elements
    SafeRunner.run(new ISafeRunnable() {

        @Override
        public void handleException(Throwable e) {
            if (e instanceof Error) {
                // errors are deadly, we shouldn't ignore these
                throw (Error) e;
            }
            // log exceptions otherwise
            if (logger != null) {
                // $NON-NLS-1$
                String message = "Exception occurred while rendering: {0}";
                logger.error(e, NLS.bind(message, element));
            }
        }

        @Override
        public void run() throws Exception {
            gui[0] = safeCreateGui(element, parentWidget, parentContext);
        }
    });
    return gui[0];
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) TestableObject(org.eclipse.ui.testing.TestableObject) EObject(org.eclipse.emf.ecore.EObject) IOException(java.io.IOException) InjectionException(org.eclipse.e4.core.di.InjectionException) InvalidRegistryObjectException(org.eclipse.core.runtime.InvalidRegistryObjectException)

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