Skip to content

Commit

Permalink
Use new JFace action factories
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Jun 25, 2023
1 parent 9b89ec0 commit eb89e98
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.eclipse.ui.internal.progress;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
Expand Down Expand Up @@ -45,9 +46,9 @@ public class ProgressView extends ViewPart {

DetailedProgressViewer viewer;

Action cancelAction;
IAction cancelAction;

Action clearAllAction;
IAction clearAllAction;

private IPartListener2 partListener;

Expand Down Expand Up @@ -224,25 +225,15 @@ JobInfo getSelectedInfo() {
* Create the cancel action for the receiver.
*/
private void createCancelAction() {
cancelAction = new Action(ProgressMessages.ProgressView_CancelAction) {
@Override
public void run() {
viewer.cancelSelection();
}
};

cancelAction = Action.create(ProgressMessages.ProgressView_CancelAction, () -> viewer.cancelSelection());
}

/**
* Create the clear all action for the receiver.
*/
private void createClearAllAction() {
clearAllAction = new Action(ProgressMessages.ProgressView_ClearAllAction) {
@Override
public void run() {
FinishedJobs.getInstance().clearAll();
}
};
clearAllAction = Action.create(ProgressMessages.ProgressView_ClearAllAction,
() -> FinishedJobs.getInstance().clearAll());
clearAllAction.setToolTipText(ProgressMessages.NewProgressView_RemoveAllJobsToolTip);
ImageDescriptor id = WorkbenchImages.getWorkbenchImageDescriptor("/elcl16/progress_remall.png"); //$NON-NLS-1$
if (id != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.core.commands.operations.OperationHistoryEvent;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
Expand Down Expand Up @@ -75,13 +76,13 @@ public class UndoHistoryView extends ViewPart implements
ISelectionChangedListener {
private TableViewer viewer;

private Action filterAction;
private IAction filterAction;

private Action doubleClickAction;
private IAction doubleClickAction;

private Action selectiveUndoAction;
private IAction selectiveUndoAction;

private Action refreshListAction;
private IAction refreshListAction;

private IOperationHistory history = OperationHistoryFactory
.getOperationHistory();
Expand Down Expand Up @@ -331,67 +332,55 @@ private void fillContextMenu(IMenuManager manager) {
* Create the actions for the view.
*/
private void makeActions() {
filterAction = new Action() {
@Override
public void run() {
IUndoContext context = selectContext();
if (fContext != context && context != null) {
setContext(context);
}
filterAction = Action.create(() -> {
IUndoContext context = selectContext();
if (fContext != context && context != null) {
setContext(context);
}
};
});
filterAction.setText(UndoExampleMessages.UndoHistoryView_FilterText);
filterAction.setToolTipText(UndoExampleMessages.UndoHistoryView_FilterToolTipText);
filterAction.setImageDescriptor(PlatformUI.getWorkbench()
.getSharedImages().getImageDescriptor(
ISharedImages.IMG_OBJS_INFO_TSK));

selectiveUndoAction = new Action() {
@Override
public void run() {
IUndoableOperation operation = (IUndoableOperation) viewer.getStructuredSelection().getFirstElement();
if (operation.canUndo()) {
try {
history.undoOperation(operation, null, undoAction);
} catch (ExecutionException e) {
showMessage(UndoExampleMessages.UndoHistoryView_OperationException);
}
} else {
showMessage(UndoExampleMessages.UndoHistoryView_OperationInvalid);
selectiveUndoAction = Action.create(() -> {
IUndoableOperation operation = (IUndoableOperation) viewer.getStructuredSelection().getFirstElement();
if (operation.canUndo()) {
try {
history.undoOperation(operation, null, undoAction);
} catch (ExecutionException e) {
showMessage(UndoExampleMessages.UndoHistoryView_OperationException);
}
} else {
showMessage(UndoExampleMessages.UndoHistoryView_OperationInvalid);
}
};
});
selectiveUndoAction.setText(UndoExampleMessages.UndoHistoryView_UndoSelected);
selectiveUndoAction.setToolTipText(UndoExampleMessages.UndoHistoryView_UndoSelectedToolTipText);
selectiveUndoAction.setImageDescriptor(PlatformUI.getWorkbench()
.getSharedImages().getImageDescriptor(
ISharedImages.IMG_TOOL_UNDO));

refreshListAction = new Action() {
@Override
public void run() {
if (!viewer.getTable().isDisposed()) {
viewer.refresh(true);
}
refreshListAction = Action.create(() -> {
if (!viewer.getTable().isDisposed()) {
viewer.refresh(true);
}
};
});
refreshListAction.setText(UndoExampleMessages.UndoHistoryView_RefreshList);
refreshListAction.setToolTipText(UndoExampleMessages.UndoHistoryView_RefreshListToolTipText);

doubleClickAction = new Action() {
@Override
public void run() {
IUndoableOperation operation = (IUndoableOperation) viewer.getStructuredSelection().getFirstElement();
StringBuilder buf = new StringBuilder(operation.getLabel());
buf.append("\n");
buf.append("Enabled="); //$NON-NLS-1$
buf.append(Boolean.toString(operation.canUndo()));
buf.append("\n");
buf.append(operation.getClass().toString());
showMessage(buf.toString());

}
};
doubleClickAction = Action.create(() -> {
IUndoableOperation operation = (IUndoableOperation) viewer.getStructuredSelection().getFirstElement();
StringBuilder buf = new StringBuilder(operation.getLabel());
buf.append("\n");
buf.append("Enabled="); //$NON-NLS-1$
buf.append(Boolean.toString(operation.canUndo()));
buf.append("\n");
buf.append(operation.getClass().toString());
showMessage(buf.toString());

});
}

/*
Expand Down

0 comments on commit eb89e98

Please sign in to comment.