use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project eclipse.platform.text by eclipse.
the class AddMarkerAction method run.
@Override
public void run() {
IResource resource = getResource();
if (resource == null)
return;
Map<String, Object> attributes = getInitialAttributes();
if (fAskForLabel) {
if (!askForLabel(attributes))
return;
}
String name = getToolTipText();
name = name == null ? TextEditorMessages.AddMarkerAction_addMarker : name;
final Shell shell = getTextEditor().getSite().getShell();
IAdaptable context = new IAdaptable() {
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter == Shell.class)
return (T) shell;
return null;
}
};
IUndoableOperation operation = new CreateMarkersOperation(fMarkerType, attributes, resource, name);
IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
try {
operationHistory.execute(operation, null, context);
} catch (ExecutionException x) {
Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
ILog log = Platform.getLog(bundle);
// $NON-NLS-2$ //$NON-NLS-1$
String msg = getString(fBundle, fPrefix + "error.dialog.message", fPrefix + "error.dialog.message");
log.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, msg, x));
}
}
use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project eclipse.platform.text by eclipse.
the class MarkerRulerAction method addMarker.
/**
* Creates a new marker according to the specification of this action and
* adds it to the marker resource.
*/
protected void addMarker() {
IResource resource = getResource();
if (resource == null)
return;
Map<String, Object> attributes = getInitialAttributes();
if (fAskForLabel) {
if (!askForLabel(attributes))
return;
}
execute(new CreateMarkersOperation(fMarkerType, attributes, resource, getOperationName()));
}
use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project xtext-eclipse by eclipse.
the class ProblemHoverTest method testBug357516_bookmark.
@Test
public void testBug357516_bookmark() throws Exception {
IResource resource = editor.getResource();
HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(IMarker.MESSAGE, CUSTOM_MARKER_TEST_MESSAGE);
attributes.put(IMarker.LINE_NUMBER, 1);
attributes.put(IMarker.LOCATION, resource.getFullPath().toPortableString());
IUndoableOperation operation = new CreateMarkersOperation(IMarker.BOOKMARK, attributes, resource, CUSTOM_MARKER_TEST_MESSAGE);
IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
try {
operationHistory.execute(operation, null, null);
} catch (ExecutionException x) {
fail(x.getMessage());
}
String hoverInfo = hover.getHoverInfo(editor.getInternalSourceViewer(), 0);
assertNotNull(hoverInfo);
assertTrue(hoverInfo.contains(CUSTOM_MARKER_TEST_MESSAGE));
}
use of org.eclipse.ui.ide.undo.CreateMarkersOperation in project tdq-studio-se by Talend.
the class TdDialogMarkerProperties method saveChanges.
/**
* Saves the changes made in the dialog if needed. Creates a new marker if needed. Updates the existing marker only
* if there have been changes.
*/
@SuppressWarnings("unchecked")
private void saveChanges() {
Map attrs = getMarkerAttributes();
IUndoableOperation op = null;
if (marker == null) {
if (resource == null)
return;
op = new CreateMarkersOperation(type, attrs, resource, getCreateOperationTitle());
} else {
if (isDirty()) {
op = new UpdateMarkersOperation(marker, attrs, getModifyOperationTitle(), true);
}
}
if (op != null) {
try {
PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, null, WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
} catch (ExecutionException e) {
if (e.getCause() instanceof CoreException) {
ErrorDialog.openError(getShell(), MarkerMessages.Error, null, ((CoreException) e.getCause()).getStatus());
} else {
IDEWorkbenchPlugin.log(e.getMessage(), e);
}
}
}
}
Aggregations