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();
}
}
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;
}
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);
}
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);
}
}
}
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;
}
Aggregations