/** Update enabling and labels according to the current status of the operation history. */ public void update() { if (isInvalid()) { return; } boolean enabled = shouldBeEnabled(); String text, tooltipText; if (enabled) { tooltipText = NLS.bind(getTooltipString(), getOperation().getLabel()); text = NLS.bind( getCommandString(), LegacyActionTools.escapeMnemonics(shortenText(getOperation().getLabel()))) + '@'; } else { tooltipText = NLS.bind(WorkbenchMessages.Operations_undoRedoCommandDisabled, getSimpleTooltipString()); text = getSimpleCommandString(); /* * if there is nothing to do and we are pruning the history, flush * the history of this context. */ if (undoContext != null && pruning) { flush(); } } setText(text); setToolTipText(tooltipText); setEnabled(enabled); }
@Override public void updateLabel() { ISearchResultPage page = getActivePage(); String label = ""; // $NON-NLS-1$ if (page != null) { label = LegacyActionTools.escapeMnemonics(page.getLabel()); } if (!fPageContent.isDisposed()) { if (label.length() == 0) { if (fDescriptionComposite != null) { fDescriptionComposite.dispose(); fDescriptionComposite = null; fPageContent.layout(); } } else { if (fDescriptionComposite == null) { fDescriptionComposite = new Composite(fPageContent, SWT.NONE); fDescriptionComposite.moveAbove(null); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 0; fDescriptionComposite.setLayout(layout); fDescriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fDescription = new Link(fDescriptionComposite, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false); gridData.horizontalIndent = 5; fDescription.setLayoutData(gridData); fDescription.setText(label); Label separator = new Label(fDescriptionComposite, SWT.SEPARATOR | SWT.HORIZONTAL); separator.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); fPageContent.layout(); } else { fDescription.setText(label); } } } }
/** * Escapes '&' with '&' in the given text. * * @param text the text to escape, can be <code>null</code> * @return the escaped string or <code>null</code> if text was <code>null</code> * @since 3.4 */ private String escape(String text) { if (text == null) return text; return LegacyActionTools.escapeMnemonics(text); }
/** * Informs the user about the fact that there are no enabled categories in the default content * assist set and shows a link to the preferences. * * @return <code>true</code> if the default should be restored * @since 3.3 */ private boolean informUserAboutEmptyDefaultCategory() { if (OptionalMessageDialog.isDialogEnabled(PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY)) { final Shell shell = JavaPlugin.getActiveWorkbenchShell(); String title = JavaTextMessages.ContentAssistProcessor_all_disabled_title; String message = JavaTextMessages.ContentAssistProcessor_all_disabled_message; // see PreferencePage#createControl for the 'defaults' label final String restoreButtonLabel = JFaceResources.getString("defaults"); // $NON-NLS-1$ final String linkMessage = Messages.format( JavaTextMessages.ContentAssistProcessor_all_disabled_preference_link, LegacyActionTools.removeMnemonics(restoreButtonLabel)); final int restoreId = IDialogConstants.CLIENT_ID + 10; final int settingsId = IDialogConstants.CLIENT_ID + 11; final OptionalMessageDialog dialog = new OptionalMessageDialog( PREF_WARN_ABOUT_EMPTY_ASSIST_CATEGORY, shell, title, null /* default image */, message, MessageDialog.WARNING, new String[] {restoreButtonLabel, IDialogConstants.CLOSE_LABEL}, 1) { /* * @see org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite) */ @Override protected Control createCustomArea(Composite composite) { // wrap link and checkbox in one composite without space Composite parent = new Composite(composite, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 0; parent.setLayout(layout); Composite linkComposite = new Composite(parent, SWT.NONE); layout = new GridLayout(); layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); linkComposite.setLayout(layout); Link link = new Link(linkComposite, SWT.NONE); link.setText(linkMessage); link.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { setReturnCode(settingsId); close(); } }); GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gridData.widthHint = this.getMinimumMessageWidth(); link.setLayoutData(gridData); // create checkbox and "don't show this message" prompt super.createCustomArea(parent); return parent; } /* * @see org.eclipse.jface.dialogs.MessageDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) */ @Override protected void createButtonsForButtonBar(Composite parent) { Button[] buttons = new Button[2]; buttons[0] = createButton(parent, restoreId, restoreButtonLabel, false); buttons[1] = createButton( parent, IDialogConstants.CLOSE_ID, IDialogConstants.CLOSE_LABEL, true); setButtons(buttons); } }; int returnValue = dialog.open(); if (restoreId == returnValue || settingsId == returnValue) { if (restoreId == returnValue) { IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore(); store.setToDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER); store.setToDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES); } if (settingsId == returnValue) PreferencesUtil.createPreferenceDialogOn( shell, "org.eclipse.jdt.ui.preferences.CodeAssistPreferenceAdvanced", null, null) .open(); //$NON-NLS-1$ fComputerRegistry.reload(); return true; } } return false; }