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