下面列出了怎么用org.eclipse.ui.internal.WorkbenchMessages的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Create the button that clears the text.
*
* @param parent parent <code>Composite</code> of toolbar button
*/
private void createClearText(Composite parent) {
// only create the button if the text widget doesn't support one
// natively
if ((filterText.getStyle() & SWT.CANCEL) == 0) {
filterToolBar = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
filterToolBar.createControl(parent);
IAction clearTextAction = new Action("", IAction.AS_PUSH_BUTTON) {//$NON-NLS-1$
@Override
public void run() {
clearText();
}
};
clearTextAction.setToolTipText(WorkbenchMessages.FilteredTree_ClearToolTip);
clearTextAction.setImageDescriptor(XViewerImageCache.getImageDescriptor("clear.gif")); //$NON-NLS-1$
clearTextAction.setDisabledImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(DCLEAR_ICON));
filterToolBar.add(clearTextAction);
}
}
/**
* Stores dialog settings.
*
* @param settings
* settings used to store dialog
*/
protected void storeDialog(IDialogSettings settings) {
settings.put(SHOW_STATUS_LINE, toggleStatusLineAction.isChecked());
XMLMemento memento = XMLMemento.createWriteRoot(HISTORY_SETTINGS);
this.contentProvider.saveHistory(memento);
StringWriter writer = new StringWriter();
try {
memento.save(writer);
settings.put(HISTORY_SETTINGS, writer.getBuffer().toString());
} catch (IOException e) {
// Simply don't store the settings
StatusManager
.getManager()
.handle(
new Status(
IStatus.ERROR,
PlatformUI.PLUGIN_ID,
IStatus.ERROR,
WorkbenchMessages.FilteredItemsSelectionDialog_storeError,
e));
}
}
/**
* Hook that allows to add actions to the context menu.
* <p>
* Subclasses may extend in order to add other actions.</p>
*
* @param menuManager the context menu manager
* @since 3.5
*/
protected void fillContextMenu(IMenuManager menuManager) {
List selectedElements= ((StructuredSelection)list.getSelection()).toList();
Object item= null;
for (Iterator it= selectedElements.iterator(); it.hasNext();) {
item= it.next();
if (item instanceof ItemsListSeparator || !isHistoryElement(item)) {
return;
}
}
if (selectedElements.size() > 0) {
removeHistoryItemAction.setText(WorkbenchMessages.FilteredItemsSelectionDialog_removeItemsFromHistoryAction);
menuManager.add(removeHistoryActionContributionItem);
}
}
/**
* Refreshes the details field according to the current selection in the
* items list.
*/
private void refreshDetails() {
StructuredSelection selection = getSelectedItems();
switch (selection.size()) {
case 0:
details.setInput(null);
break;
case 1:
details.setInput(selection.getFirstElement());
break;
default:
details
.setInput(NLS
.bind(
WorkbenchMessages.FilteredItemsSelectionDialog_nItemsSelected,
new Integer(selection.size())));
break;
}
}
private void createFilter(final Composite listComposite) {
final Text fileStoreListFilter = new Text(listComposite,
SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
fileStoreListFilter.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
fileStoreListFilter.setMessage(WorkbenchMessages.FilteredTree_FilterMessage);
fileStoreListFilter.addModifyListener(new ModifyListener() {
private ViewerFilter filter;
@Override
public void modifyText(final ModifyEvent e) {
final String textForFiltering = fileStoreListFilter.getText();
if (filter != null) {
fileStoreListViewer.removeFilter(filter);
}
if (textForFiltering != null
&& !textForFiltering.isEmpty()) {
filter = new ViewerFilterOnFileStoreName(textForFiltering);
fileStoreListViewer.addFilter(filter);
}
}
});
}
/**
* Create an instance of the AboutDialog for the given window.
* @param parentShell The parent of the dialog.
*/
public AboutDialog(Shell parentShell) {
super(parentShell);
product = Platform.getProduct();
if (product != null) {
productName = product.getName();
}
if (productName == null) {
productName = WorkbenchMessages.AboutDialog_defaultProductName;
}
// create a descriptive object for each BundleGroup
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders();
LinkedList groups = new LinkedList();
if (providers != null) {
for (int i = 0; i < providers.length; ++i) {
IBundleGroup[] bundleGroups = providers[i].getBundleGroups();
for (int j = 0; j < bundleGroups.length; ++j) {
groups.add(new AboutBundleGroupData(bundleGroups[j]));
}
}
}
bundleGroupInfos = (AboutBundleGroupData[]) groups
.toArray(new AboutBundleGroupData[0]);
}
/**
* Add buttons to the dialog's button bar.
*
* Subclasses should override.
*
* @param parent
* the button bar composite
*/
protected void createButtonsForButtonBar(Composite parent) {
parent.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
createButton(parent, DETAILS_ID, WorkbenchMessages.AboutDialog_DetailsButton, false);
Label l = new Label(parent, SWT.NONE);
l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
GridLayout layout = (GridLayout) parent.getLayout();
layout.numColumns++;
layout.makeColumnsEqualWidth = false;
Button b = createButton(parent, IDialogConstants.OK_ID,
IDialogConstants.OK_LABEL, true);
b.setFocus();
}
/**
* Create the filtered tree.
*
* @param treeStyle the style bits for the <code>Tree</code>
* @param filter the filter to be used
* @since 3.3
*/
protected void init(int treeStyle, PatternFilter filter) {
patternFilter = filter;
showFilterControls = true;
if (!XViewerDisplay.isStandaloneXViewer() && XViewerDisplay.isWorkbenchRunning()) {
showFilterControls =
PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_FILTERED_TEXTS);
}
createControl(parent, treeStyle);
createRefreshJob();
setInitialText(WorkbenchMessages.FilteredTree_FilterMessage);
setFont(parent.getFont());
}
/**
* Creates a new instance of the class.
*
* @param shell
* shell to parent the dialog on
* @param multi
* indicates whether dialog allows to select more than one
* position in its list of items
*/
public FilteredItemsSelectionDialog(Shell shell, boolean multi) {
super(shell);
this.multi = multi;
filterHistoryJob = new FilterHistoryJob();
filterJob = new FilterJob();
contentProvider = new ContentProvider();
refreshCacheJob = new RefreshCacheJob();
itemsListSeparator = new ItemsListSeparator(
WorkbenchMessages.FilteredItemsSelectionDialog_separatorLabel);
selectionMode = NONE;
}
/**
* Restores dialog using persisted settings. The default implementation
* restores the status of the details line and the selection history.
*
* @param settings
* settings used to restore dialog
*/
protected void restoreDialog(IDialogSettings settings) {
boolean toggleStatusLine = true;
if (settings.get(SHOW_STATUS_LINE) != null) {
toggleStatusLine = settings.getBoolean(SHOW_STATUS_LINE);
}
toggleStatusLineAction.setChecked(toggleStatusLine);
details.setVisible(toggleStatusLine);
String setting = settings.get(HISTORY_SETTINGS);
if (setting != null) {
try {
IMemento memento = XMLMemento.createReadRoot(new StringReader(
setting));
this.contentProvider.loadHistory(memento);
} catch (WorkbenchException e) {
// Simply don't restore the settings
StatusManager
.getManager()
.handle(
new Status(
IStatus.ERROR,
PlatformUI.PLUGIN_ID,
IStatus.ERROR,
WorkbenchMessages.FilteredItemsSelectionDialog_restoreError,
e));
}
}
}
/**
* Create a new header which is labelled by headerLabel.
*
* @param parent
* @return Label the label of the header
*/
private Label createHeader(Composite parent) {
Composite header = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.marginHeight = 0;
header.setLayout(layout);
Label headerLabel = new Label(header, SWT.NONE);
headerLabel.setText((getMessage() != null && getMessage().trim()
.length() > 0) ? getMessage()
: WorkbenchMessages.FilteredItemsSelectionDialog_patternLabel);
headerLabel.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
e.detail = SWT.TRAVERSE_NONE;
pattern.setFocus();
}
}
});
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
headerLabel.setLayoutData(gd);
createViewMenu(header);
header.setLayoutData(gd);
return headerLabel;
}
/**
* Create the labels for the list and the progress. Return the list label.
*
* @param parent
* @return Label
*/
private Label createLabels(Composite parent) {
Composite labels = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.marginHeight = 0;
labels.setLayout(layout);
Label listLabel = new Label(labels, SWT.NONE);
listLabel
.setText(WorkbenchMessages.FilteredItemsSelectionDialog_listLabel);
listLabel.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
e.detail = SWT.TRAVERSE_NONE;
list.getTable().setFocus();
}
}
});
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
listLabel.setLayoutData(gd);
progressLabel = new Label(labels, SWT.RIGHT);
progressLabel.setLayoutData(gd);
labels.setLayoutData(gd);
return listLabel;
}
/**
* Creates a new instance of the class.
*/
public RefreshJob() {
super(FilteredItemsSelectionDialog.this.getParentShell()
.getDisplay(),
WorkbenchMessages.FilteredItemsSelectionDialog_refreshJob);
setSystem(true);
}
/**
* Creates a new instance of the class.
*/
public RefreshProgressMessageJob() {
super(
FilteredItemsSelectionDialog.this.getParentShell()
.getDisplay(),
WorkbenchMessages.FilteredItemsSelectionDialog_progressRefreshJob);
setSystem(true);
}
private String getMessage() {
if (done)
return ""; //$NON-NLS-1$
String message;
if (name == null) {
message = subName == null ? "" : subName; //$NON-NLS-1$
} else {
message = subName == null ? name
: NLS
.bind(
WorkbenchMessages.FilteredItemsSelectionDialog_subtaskProgressMessage,
new Object[] { name, subName });
}
if (totalWork == 0)
return message;
return NLS
.bind(
WorkbenchMessages.FilteredItemsSelectionDialog_taskProgressMessage,
new Object[] {
message,
new Integer(
(int) ((worked * 100) / totalWork)) });
}
/**
* Executes job using the given filtering progress monitor. A hook for
* subclasses.
*
* @param monitor
* progress monitor
* @return result of the execution
*/
protected IStatus doRun(GranualProgressMonitor monitor) {
try {
internalRun(monitor);
} catch (CoreException e) {
cancel();
return new Status(
IStatus.ERROR,
PlatformUI.PLUGIN_ID,
IStatus.ERROR,
WorkbenchMessages.FilteredItemsSelectionDialog_jobError,
e);
}
return Status.OK_STATUS;
}
/**
* Main method responsible for getting the filtered items and checking
* for duplicates. It is based on the
* {@link FilteredItemsSelectionDialog.ContentProvider#getFilteredItems(Object, IProgressMonitor)}.
*
* @param checkDuplicates
* <code>true</code> if data concerning elements
* duplication should be computed - it takes much more time
* than standard filtering
*
* @param monitor
* progress monitor
*/
public void reloadCache(boolean checkDuplicates,
IProgressMonitor monitor) {
reset = false;
if (monitor != null) {
// the work is divided into two actions of the same length
int totalWork = checkDuplicates ? 200 : 100;
monitor
.beginTask(
WorkbenchMessages.FilteredItemsSelectionDialog_cacheRefreshJob,
totalWork);
}
// the TableViewer's root (the input) is treated as parent
lastFilteredItems = Arrays.asList(getFilteredItems(list.getInput(),
monitor != null ? new SubProgressMonitor(monitor, 100)
: null));
if (reset || (monitor != null && monitor.isCanceled())) {
if (monitor != null)
monitor.done();
return;
}
if (checkDuplicates) {
checkDuplicates(monitor);
}
if (monitor != null)
monitor.done();
}
OpenPreferencesAction() {
super(WorkbenchMessages.OpenPreferences_text);
setId("preferences");
setText("Preferences");
setToolTipText("Open GAMA preferences");
setImageDescriptor(icons.desc("menu.open.preferences2"));
window.getWorkbench().getHelpSystem().setHelp(this, IWorkbenchHelpContextIds.OPEN_PREFERENCES_ACTION);
}
public PropertyLinkArea(Composite parent, int style, final String pageId, IAdaptable element, String message,
final IWorkbenchPreferenceContainer pageContainer)
{
this.element = element;
pageLink = new Link(parent, style);
IPreferenceNode node = getPreferenceNode(pageId);
String text = null;
if (node == null)
{
text = NLS.bind(WorkbenchMessages.PreferenceNode_NotFound, pageId);
}
else
{
text = NLS.bind(message, node.getLabelText());
}
pageLink.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
pageContainer.openPage(pageId, null);
}
});
pageLink.setText(text);
}
public PropToPrefLinkArea(Composite parent, int style, final String pageId, String message, final Shell shell,
final Object pageData)
{
/*
* breaking new ground yet again - want to link between property and preference paes. ie: project specific debug
* engine options to general debugging options
*/
pageLink = new Link(parent, style);
IPreferenceNode node = getPreferenceNode(pageId);
String result;
if (node == null)
{
result = NLS.bind(WorkbenchMessages.PreferenceNode_NotFound, pageId);
}
else
{
result = MessageFormat.format(message, node.getLabelText());
// only add the selection listener if the node is found
pageLink.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent e)
{
PreferencesUtil.createPreferenceDialogOn(shell, pageId, new String[] { pageId }, pageData).open();
}
});
}
pageLink.setText(result);
}
protected CopyAction() {
super(WorkbenchMessages.Workbench_copy);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
}
protected PasteAction() {
super(WorkbenchMessages.Workbench_paste);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
}
protected CutAction() {
super(WorkbenchMessages.Workbench_cut);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT_DISABLED));
}
protected UndoAction() {
super(WorkbenchMessages.Workbench_undo);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
}
protected RedoAction() {
super(WorkbenchMessages.Workbench_redo);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO_DISABLED));
}
CopyAction() {
super(WorkbenchMessages.Workbench_copy);
ISharedImages sharedImages = view.getSite().getWorkbenchWindow().getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
setEnabled(false);
}
@SuppressWarnings("restriction")
protected PasteActionHandler() {
super(WorkbenchMessages.Workbench_paste);
setId("ProperPasteAttribute");//$NON-NLS-1$
setActionDefinitionId(ActionFactory.PASTE.getCommandId());
setImageDescriptor(Activator.getImageDescriptor("images/menu/edit/paste.png"));
setEnabled(true);
}
protected CopyActionHandler() {
super(WorkbenchMessages.Workbench_copy);
setId("ProperCopyAttribute");//$NON-NLS-1$
setEnabled(true);
setImageDescriptor(Activator.getImageDescriptor("images/menu/edit/copy.png"));
setActionDefinitionId(ActionFactory.COPY.getCommandId());
}
protected CopyAction() {
super(WorkbenchMessages.Workbench_copy);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
}
protected PasteAction() {
super(WorkbenchMessages.Workbench_paste);
setEnabled(false);
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
}