|
Lines 16-23
Link Here
|
| 16 |
import java.util.Date; |
16 |
import java.util.Date; |
| 17 |
import java.util.Iterator; |
17 |
import java.util.Iterator; |
| 18 |
import java.util.List; |
18 |
import java.util.List; |
|
|
19 |
import org.eclipse.core.commands.ExecutionException; |
| 20 |
import org.eclipse.core.commands.NotEnabledException; |
| 21 |
import org.eclipse.core.commands.NotHandledException; |
| 22 |
import org.eclipse.core.commands.common.NotDefinedException; |
| 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
23 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 20 |
import org.eclipse.core.runtime.IStatus; |
24 |
import org.eclipse.core.runtime.IStatus; |
|
|
25 |
import org.eclipse.core.runtime.Status; |
| 21 |
import org.eclipse.core.runtime.jobs.Job; |
26 |
import org.eclipse.core.runtime.jobs.Job; |
| 22 |
import org.eclipse.jface.action.IAction; |
27 |
import org.eclipse.jface.action.IAction; |
| 23 |
import org.eclipse.jface.dialogs.Dialog; |
28 |
import org.eclipse.jface.dialogs.Dialog; |
|
Lines 50-56
Link Here
|
| 50 |
import org.eclipse.swt.widgets.ToolBar; |
55 |
import org.eclipse.swt.widgets.ToolBar; |
| 51 |
import org.eclipse.swt.widgets.ToolItem; |
56 |
import org.eclipse.swt.widgets.ToolItem; |
| 52 |
import org.eclipse.ui.PlatformUI; |
57 |
import org.eclipse.ui.PlatformUI; |
|
|
58 |
import org.eclipse.ui.handlers.IHandlerService; |
| 53 |
import org.eclipse.ui.internal.WorkbenchImages; |
59 |
import org.eclipse.ui.internal.WorkbenchImages; |
|
|
60 |
import org.eclipse.ui.internal.WorkbenchPlugin; |
| 54 |
import org.eclipse.ui.progress.IProgressConstants; |
61 |
import org.eclipse.ui.progress.IProgressConstants; |
| 55 |
|
62 |
|
| 56 |
/** |
63 |
/** |
|
Lines 93-99
Link Here
|
| 93 |
|
100 |
|
| 94 |
private static final String TEXT_KEY = "Text"; //$NON-NLS-1$ |
101 |
private static final String TEXT_KEY = "Text"; //$NON-NLS-1$ |
| 95 |
|
102 |
|
| 96 |
private static final String ACTION_KEY = "Action";//$NON-NLS-1$ |
103 |
private static final String TRIGGER_KEY = "Trigger";//$NON-NLS-1$ |
|
|
104 |
|
| 105 |
boolean triggerWarningLogged = false; |
| 97 |
|
106 |
|
| 98 |
interface IndexListener { |
107 |
interface IndexListener { |
| 99 |
/** |
108 |
/** |
|
Lines 124-129
Link Here
|
| 124 |
|
133 |
|
| 125 |
private ResourceManager resourceManager; |
134 |
private ResourceManager resourceManager; |
| 126 |
|
135 |
|
|
|
136 |
private Link link; |
| 137 |
|
| 127 |
static { |
138 |
static { |
| 128 |
JFaceResources |
139 |
JFaceResources |
| 129 |
.getImageRegistry() |
140 |
.getImageRegistry() |
|
Lines 222-237
Link Here
|
| 222 |
// busy |
233 |
// busy |
| 223 |
|
234 |
|
| 224 |
// cursor we might have |
235 |
// cursor we might have |
| 225 |
actionButton = new ToolItem(actionBar, SWT.NONE); |
236 |
if (info.isCancellable()) { |
| 226 |
actionButton |
237 |
actionButton = new ToolItem(actionBar, SWT.NONE); |
| 227 |
.setToolTipText(ProgressMessages.NewProgressView_CancelJobToolTip); |
238 |
actionButton |
| 228 |
actionButton.addSelectionListener(new SelectionAdapter() { |
239 |
.setToolTipText(ProgressMessages.NewProgressView_CancelJobToolTip); |
| 229 |
public void widgetSelected(SelectionEvent e) { |
240 |
actionButton.addSelectionListener(new SelectionAdapter() { |
| 230 |
actionButton.setEnabled(false); |
241 |
public void widgetSelected(SelectionEvent e) { |
| 231 |
cancelOrRemove(); |
242 |
actionButton.setEnabled(false); |
| 232 |
} |
243 |
cancelOrRemove(); |
| 233 |
|
244 |
} |
| 234 |
}); |
245 |
}); |
|
|
246 |
} |
| 247 |
|
| 235 |
actionBar.addListener(SWT.Traverse, new Listener() { |
248 |
actionBar.addListener(SWT.Traverse, new Listener() { |
| 236 |
/* |
249 |
/* |
| 237 |
* (non-Javadoc) |
250 |
* (non-Javadoc) |
|
Lines 654-659
Link Here
|
| 654 |
* |
667 |
* |
| 655 |
*/ |
668 |
*/ |
| 656 |
private void updateToolBarValues() { |
669 |
private void updateToolBarValues() { |
|
|
670 |
if (actionButton == null) { |
| 671 |
return; |
| 672 |
} |
| 657 |
if (isCompleted()) { |
673 |
if (isCompleted()) { |
| 658 |
actionButton.setImage(JFaceResources |
674 |
actionButton.setImage(JFaceResources |
| 659 |
.getImage(CLEAR_FINISHED_JOB_KEY)); |
675 |
.getImage(CLEAR_FINISHED_JOB_KEY)); |
|
Lines 726-732
Link Here
|
| 726 |
*/ |
742 |
*/ |
| 727 |
void setLinkText(Job linkJob, String taskString, int index) { |
743 |
void setLinkText(Job linkJob, String taskString, int index) { |
| 728 |
|
744 |
|
| 729 |
Link link; |
|
|
| 730 |
if (index >= taskEntries.size()) {// Is it new? |
745 |
if (index >= taskEntries.size()) {// Is it new? |
| 731 |
link = new Link(this, SWT.NONE); |
746 |
link = new Link(this, SWT.NONE); |
| 732 |
|
747 |
|
|
Lines 754-761
Link Here
|
| 754 |
|
769 |
|
| 755 |
link.setLayoutData(linkData); |
770 |
link.setLayoutData(linkData); |
| 756 |
|
771 |
|
| 757 |
final Link finalLink = link; |
|
|
| 758 |
|
| 759 |
link.addSelectionListener(new SelectionAdapter() { |
772 |
link.addSelectionListener(new SelectionAdapter() { |
| 760 |
/* |
773 |
/* |
| 761 |
* (non-Javadoc) |
774 |
* (non-Javadoc) |
|
Lines 764-780
Link Here
|
| 764 |
*/ |
777 |
*/ |
| 765 |
public void widgetSelected(SelectionEvent e) { |
778 |
public void widgetSelected(SelectionEvent e) { |
| 766 |
|
779 |
|
| 767 |
IAction action = (IAction) finalLink.getData(ACTION_KEY); |
780 |
executeTrigger(); |
| 768 |
action.run(); |
|
|
| 769 |
|
| 770 |
updateAction(action, finalLink); |
| 771 |
|
| 772 |
Object text = finalLink.getData(TEXT_KEY); |
| 773 |
if (text == null) |
| 774 |
return; |
| 775 |
|
| 776 |
// Refresh the text as enablement might have changed |
| 777 |
updateText((String) text, finalLink); |
| 778 |
} |
781 |
} |
| 779 |
}); |
782 |
}); |
| 780 |
|
783 |
|
|
Lines 786-796
Link Here
|
| 786 |
*/ |
789 |
*/ |
| 787 |
public void handleEvent(Event event) { |
790 |
public void handleEvent(Event event) { |
| 788 |
|
791 |
|
| 789 |
Object text = finalLink.getData(TEXT_KEY); |
792 |
Object text = link.getData(TEXT_KEY); |
| 790 |
if (text == null) |
793 |
if (text == null) |
| 791 |
return; |
794 |
return; |
| 792 |
|
795 |
|
| 793 |
updateText((String) text, finalLink); |
796 |
updateText((String) text, link); |
| 794 |
|
797 |
|
| 795 |
} |
798 |
} |
| 796 |
}); |
799 |
}); |
|
Lines 803-830
Link Here
|
| 803 |
link.setData(TEXT_KEY, taskString); |
806 |
link.setData(TEXT_KEY, taskString); |
| 804 |
|
807 |
|
| 805 |
// check for action property |
808 |
// check for action property |
| 806 |
Object property = linkJob |
809 |
Object actionProperty = linkJob |
| 807 |
.getProperty(IProgressConstants.ACTION_PROPERTY); |
810 |
.getProperty(IProgressConstants.ACTION_PROPERTY); |
| 808 |
updateAction(property, link); |
811 |
Object commandProperty = linkJob |
|
|
812 |
.getProperty(IProgressConstants.COMMAND_PROPERTY); |
| 813 |
|
| 814 |
if (actionProperty != null && commandProperty != null) { |
| 815 |
// if both are specified, then use neither |
| 816 |
updateAction(null, link); |
| 817 |
} else { |
| 818 |
Object property = actionProperty == null ? commandProperty |
| 819 |
: actionProperty; |
| 820 |
updateAction(property, link); |
| 821 |
} |
| 809 |
|
822 |
|
| 810 |
updateText(taskString, link); |
823 |
updateText(taskString, link); |
| 811 |
|
824 |
|
| 812 |
} |
825 |
} |
| 813 |
|
826 |
|
|
|
827 |
public void executeTrigger() { |
| 828 |
|
| 829 |
Object data = link.getData(TRIGGER_KEY); |
| 830 |
if (data instanceof IAction) { |
| 831 |
IAction action = (IAction) data; |
| 832 |
action.run(); |
| 833 |
updateAction(action, link); |
| 834 |
} else if (data instanceof String) { |
| 835 |
IHandlerService handlerService = (IHandlerService) PlatformUI |
| 836 |
.getWorkbench().getService(IHandlerService.class); |
| 837 |
IStatus status = Status.OK_STATUS; |
| 838 |
try { |
| 839 |
handlerService.executeCommand((String) data, null); |
| 840 |
} catch (ExecutionException e) { |
| 841 |
status = new Status( |
| 842 |
IStatus.ERROR, |
| 843 |
PlatformUI.PLUGIN_ID, |
| 844 |
"An error occured while executing the command specified on the Job", e); //$NON-NLS-1$ |
| 845 |
} catch (NotDefinedException e) { |
| 846 |
status = new Status( |
| 847 |
IStatus.ERROR, |
| 848 |
PlatformUI.PLUGIN_ID, |
| 849 |
"An error occured while executing the command specified on the Job", e); //$NON-NLS-1$ |
| 850 |
} catch (NotEnabledException e) { |
| 851 |
status = new Status(IStatus.WARNING, PlatformUI.PLUGIN_ID, |
| 852 |
"The command specified on the job is not disabled", e); //$NON-NLS-1$ |
| 853 |
} catch (NotHandledException e) { |
| 854 |
status = new Status( |
| 855 |
IStatus.ERROR, |
| 856 |
PlatformUI.PLUGIN_ID, |
| 857 |
"An error occured while executing the command specified on the Job", e); //$NON-NLS-1$ |
| 858 |
} |
| 859 |
|
| 860 |
if (!status.isOK()) { |
| 861 |
WorkbenchPlugin.log(status); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
Object text = link.getData(TEXT_KEY); |
| 866 |
if (text == null) |
| 867 |
return; |
| 868 |
|
| 869 |
// Refresh the text as enablement might have changed |
| 870 |
updateText((String) text, link); |
| 871 |
} |
| 872 |
|
| 814 |
/** |
873 |
/** |
| 815 |
* Update the action key if action is enabled or remove it if not |
874 |
* Update the trigger key if either action is available and enabled or |
|
|
875 |
* command is available |
| 816 |
* |
876 |
* |
| 817 |
* @param action |
877 |
* @param trigger |
| 818 |
* {@link Object} or <code>null</code> |
878 |
* {@link Object} or <code>null</code> |
| 819 |
* @param link |
879 |
* @param link |
| 820 |
*/ |
880 |
*/ |
| 821 |
private void updateAction(Object action, Link link) { |
881 |
private void updateAction(Object trigger, Link link) { |
| 822 |
|
882 |
|
| 823 |
if (action != null && action instanceof IAction |
883 |
if (trigger instanceof IAction && ((IAction) trigger).isEnabled()) { |
| 824 |
&& ((IAction) action).isEnabled()) |
884 |
link.setData(TRIGGER_KEY, trigger); |
| 825 |
link.setData(ACTION_KEY, action); |
885 |
} else if (trigger instanceof String) { |
| 826 |
else |
886 |
link.setData(TRIGGER_KEY, trigger); |
| 827 |
link.setData(ACTION_KEY, null); |
887 |
} else { |
|
|
888 |
link.setData(TRIGGER_KEY, null); |
| 889 |
} |
| 828 |
|
890 |
|
| 829 |
} |
891 |
} |
| 830 |
|
892 |
|
|
Lines 838-844
Link Here
|
| 838 |
taskString = Dialog.shortenText(taskString, link); |
900 |
taskString = Dialog.shortenText(taskString, link); |
| 839 |
|
901 |
|
| 840 |
// Put in a hyperlink if there is an action |
902 |
// Put in a hyperlink if there is an action |
| 841 |
link.setText(link.getData(ACTION_KEY) == null ? taskString : NLS.bind( |
903 |
link.setText(link.getData(TRIGGER_KEY) == null ? taskString : NLS.bind( |
| 842 |
"<a>{0}</a>", taskString));//$NON-NLS-1$ |
904 |
"<a>{0}</a>", taskString));//$NON-NLS-1$ |
| 843 |
} |
905 |
} |
| 844 |
|
906 |
|