|
Lines 1-7
Link Here
|
| 1 |
package org.eclipse.ui.internal.progress; |
1 |
package org.eclipse.ui.internal.progress; |
| 2 |
|
2 |
|
| 3 |
/******************************************************************************* |
3 |
/******************************************************************************* |
| 4 |
* Copyright (c) 2005, 2008 IBM Corporation and others. |
4 |
* Copyright (c) 2005, 2009 IBM Corporation and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v1.0 |
6 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 7 |
* which accompanies this distribution, and is available at |
7 |
* which accompanies this distribution, and is available at |
|
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.ParameterizedCommand; |
| 23 |
import org.eclipse.core.commands.common.NotDefinedException; |
| 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
24 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 20 |
import org.eclipse.core.runtime.IStatus; |
25 |
import org.eclipse.core.runtime.IStatus; |
|
|
26 |
import org.eclipse.core.runtime.Status; |
| 21 |
import org.eclipse.core.runtime.jobs.Job; |
27 |
import org.eclipse.core.runtime.jobs.Job; |
| 22 |
import org.eclipse.jface.action.IAction; |
28 |
import org.eclipse.jface.action.IAction; |
| 23 |
import org.eclipse.jface.dialogs.Dialog; |
29 |
import org.eclipse.jface.dialogs.Dialog; |
|
Lines 49-57
Link Here
|
| 49 |
import org.eclipse.swt.widgets.ProgressBar; |
55 |
import org.eclipse.swt.widgets.ProgressBar; |
| 50 |
import org.eclipse.swt.widgets.ToolBar; |
56 |
import org.eclipse.swt.widgets.ToolBar; |
| 51 |
import org.eclipse.swt.widgets.ToolItem; |
57 |
import org.eclipse.swt.widgets.ToolItem; |
|
|
58 |
import org.eclipse.ui.IWorkbench; |
| 52 |
import org.eclipse.ui.PlatformUI; |
59 |
import org.eclipse.ui.PlatformUI; |
|
|
60 |
import org.eclipse.ui.handlers.IHandlerService; |
| 53 |
import org.eclipse.ui.internal.WorkbenchImages; |
61 |
import org.eclipse.ui.internal.WorkbenchImages; |
| 54 |
import org.eclipse.ui.progress.IProgressConstants; |
62 |
import org.eclipse.ui.progress.IProgressConstants; |
|
|
63 |
import org.eclipse.ui.statushandlers.StatusManager; |
| 55 |
|
64 |
|
| 56 |
/** |
65 |
/** |
| 57 |
* ProgressInfoItem is the item used to show jobs. |
66 |
* ProgressInfoItem is the item used to show jobs. |
|
Lines 93-99
Link Here
|
| 93 |
|
102 |
|
| 94 |
private static final String TEXT_KEY = "Text"; //$NON-NLS-1$ |
103 |
private static final String TEXT_KEY = "Text"; //$NON-NLS-1$ |
| 95 |
|
104 |
|
| 96 |
private static final String ACTION_KEY = "Action";//$NON-NLS-1$ |
105 |
private static final String TRIGGER_KEY = "Trigger";//$NON-NLS-1$ |
| 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 231-237
Link Here
|
| 231 |
actionButton.setEnabled(false); |
242 |
actionButton.setEnabled(false); |
| 232 |
cancelOrRemove(); |
243 |
cancelOrRemove(); |
| 233 |
} |
244 |
} |
| 234 |
|
|
|
| 235 |
}); |
245 |
}); |
| 236 |
actionBar.addListener(SWT.Traverse, new Listener() { |
246 |
actionBar.addListener(SWT.Traverse, new Listener() { |
| 237 |
/* |
247 |
/* |
|
Lines 728-734
Link Here
|
| 728 |
*/ |
738 |
*/ |
| 729 |
void setLinkText(Job linkJob, String taskString, int index) { |
739 |
void setLinkText(Job linkJob, String taskString, int index) { |
| 730 |
|
740 |
|
| 731 |
Link link; |
|
|
| 732 |
if (index >= taskEntries.size()) {// Is it new? |
741 |
if (index >= taskEntries.size()) {// Is it new? |
| 733 |
link = new Link(this, SWT.NONE); |
742 |
link = new Link(this, SWT.NONE); |
| 734 |
|
743 |
|
|
Lines 756-763
Link Here
|
| 756 |
|
765 |
|
| 757 |
link.setLayoutData(linkData); |
766 |
link.setLayoutData(linkData); |
| 758 |
|
767 |
|
| 759 |
final Link finalLink = link; |
|
|
| 760 |
|
| 761 |
link.addSelectionListener(new SelectionAdapter() { |
768 |
link.addSelectionListener(new SelectionAdapter() { |
| 762 |
/* |
769 |
/* |
| 763 |
* (non-Javadoc) |
770 |
* (non-Javadoc) |
|
Lines 765-782
Link Here
|
| 765 |
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
772 |
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
| 766 |
*/ |
773 |
*/ |
| 767 |
public void widgetSelected(SelectionEvent e) { |
774 |
public void widgetSelected(SelectionEvent e) { |
| 768 |
|
775 |
executeTrigger(); |
| 769 |
IAction action = (IAction) finalLink.getData(ACTION_KEY); |
|
|
| 770 |
action.run(); |
| 771 |
|
| 772 |
updateAction(action, finalLink); |
| 773 |
|
| 774 |
Object text = finalLink.getData(TEXT_KEY); |
| 775 |
if (text == null) |
| 776 |
return; |
| 777 |
|
| 778 |
// Refresh the text as enablement might have changed |
| 779 |
updateText((String) text, finalLink); |
| 780 |
} |
776 |
} |
| 781 |
}); |
777 |
}); |
| 782 |
|
778 |
|
|
Lines 788-798
Link Here
|
| 788 |
*/ |
784 |
*/ |
| 789 |
public void handleEvent(Event event) { |
785 |
public void handleEvent(Event event) { |
| 790 |
|
786 |
|
| 791 |
Object text = finalLink.getData(TEXT_KEY); |
787 |
Object text = link.getData(TEXT_KEY); |
| 792 |
if (text == null) |
788 |
if (text == null) |
| 793 |
return; |
789 |
return; |
| 794 |
|
790 |
|
| 795 |
updateText((String) text, finalLink); |
791 |
updateText((String) text, link); |
| 796 |
|
792 |
|
| 797 |
} |
793 |
} |
| 798 |
}); |
794 |
}); |
|
Lines 805-832
Link Here
|
| 805 |
link.setData(TEXT_KEY, taskString); |
801 |
link.setData(TEXT_KEY, taskString); |
| 806 |
|
802 |
|
| 807 |
// check for action property |
803 |
// check for action property |
| 808 |
Object property = linkJob |
804 |
Object actionProperty = linkJob |
| 809 |
.getProperty(IProgressConstants.ACTION_PROPERTY); |
805 |
.getProperty(IProgressConstants.ACTION_PROPERTY); |
| 810 |
updateAction(property, link); |
806 |
Object commandProperty = linkJob |
|
|
807 |
.getProperty(IProgressConstants.COMMAND_PROPERTY); |
| 808 |
|
| 809 |
if (actionProperty != null && commandProperty != null) { |
| 810 |
// if both are specified, then use neither |
| 811 |
updateTrigger(null, link); |
| 812 |
} else { |
| 813 |
Object property = actionProperty != null ? actionProperty |
| 814 |
: commandProperty; |
| 815 |
updateTrigger(property, link); |
| 816 |
} |
| 811 |
|
817 |
|
| 812 |
updateText(taskString, link); |
818 |
updateText(taskString, link); |
| 813 |
|
819 |
|
| 814 |
} |
820 |
} |
| 815 |
|
821 |
|
|
|
822 |
public void executeTrigger() { |
| 823 |
|
| 824 |
Object data = link.getData(TRIGGER_KEY); |
| 825 |
if (data instanceof IAction) { |
| 826 |
IAction action = (IAction) data; |
| 827 |
if (action.isEnabled()) |
| 828 |
action.run(); |
| 829 |
updateTrigger(action, link); |
| 830 |
} else if (data instanceof ParameterizedCommand) { |
| 831 |
IWorkbench workbench = PlatformUI |
| 832 |
.getWorkbench(); |
| 833 |
IHandlerService handlerService = (IHandlerService) workbench |
| 834 |
.getService( |
| 835 |
IHandlerService.class); |
| 836 |
IStatus status = Status.OK_STATUS; |
| 837 |
try { |
| 838 |
handlerService |
| 839 |
.executeCommand((ParameterizedCommand) data, null); |
| 840 |
} catch (ExecutionException e) { |
| 841 |
status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e |
| 842 |
.getMessage(), e); |
| 843 |
} catch (NotDefinedException e) { |
| 844 |
status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e |
| 845 |
.getMessage(), e); |
| 846 |
} catch (NotEnabledException e) { |
| 847 |
status = new Status(IStatus.WARNING, PlatformUI.PLUGIN_ID, e |
| 848 |
.getMessage(), e); |
| 849 |
} catch (NotHandledException e) { |
| 850 |
status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, e |
| 851 |
.getMessage(), e); |
| 852 |
} |
| 853 |
|
| 854 |
if (!status.isOK()) { |
| 855 |
StatusManager.getManager().handle(status, |
| 856 |
StatusManager.LOG | StatusManager.SHOW); |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
Object text = link.getData(TEXT_KEY); |
| 861 |
if (text == null) |
| 862 |
return; |
| 863 |
|
| 864 |
// Refresh the text as enablement might have changed |
| 865 |
updateText((String) text, link); |
| 866 |
} |
| 867 |
|
| 816 |
/** |
868 |
/** |
| 817 |
* Update the action key if action is enabled or remove it if not |
869 |
* Update the trigger key if either action is available and enabled or |
|
|
870 |
* command is available |
| 818 |
* |
871 |
* |
| 819 |
* @param action |
872 |
* @param trigger |
| 820 |
* {@link Object} or <code>null</code> |
873 |
* {@link Object} or <code>null</code> |
| 821 |
* @param link |
874 |
* @param link |
| 822 |
*/ |
875 |
*/ |
| 823 |
private void updateAction(Object action, Link link) { |
876 |
private void updateTrigger(Object trigger, Link link) { |
| 824 |
|
877 |
|
| 825 |
if (action != null && action instanceof IAction |
878 |
if (trigger instanceof IAction && ((IAction) trigger).isEnabled()) { |
| 826 |
&& ((IAction) action).isEnabled()) |
879 |
link.setData(TRIGGER_KEY, trigger); |
| 827 |
link.setData(ACTION_KEY, action); |
880 |
} else if (trigger instanceof ParameterizedCommand) { |
| 828 |
else |
881 |
link.setData(TRIGGER_KEY, trigger); |
| 829 |
link.setData(ACTION_KEY, null); |
882 |
} else { |
|
|
883 |
link.setData(TRIGGER_KEY, null); |
| 884 |
} |
| 830 |
|
885 |
|
| 831 |
} |
886 |
} |
| 832 |
|
887 |
|
|
Lines 840-846
Link Here
|
| 840 |
taskString = Dialog.shortenText(taskString, link); |
895 |
taskString = Dialog.shortenText(taskString, link); |
| 841 |
|
896 |
|
| 842 |
// Put in a hyperlink if there is an action |
897 |
// Put in a hyperlink if there is an action |
| 843 |
link.setText(link.getData(ACTION_KEY) == null ? taskString : NLS.bind( |
898 |
link.setText(link.getData(TRIGGER_KEY) == null ? taskString : NLS.bind( |
| 844 |
"<a>{0}</a>", taskString));//$NON-NLS-1$ |
899 |
"<a>{0}</a>", taskString));//$NON-NLS-1$ |
| 845 |
} |
900 |
} |
| 846 |
|
901 |
|