private String getIndentMode() { String indentMode = JavaPlugin.getDefault() .getCombinedPreferenceStore() .getString(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); if (JavaCore.SPACE.equals(indentMode)) return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_spaces; if (JavaCore.TAB.equals(indentMode)) return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tabs; if (DefaultCodeFormatterConstants.MIXED.equals(indentMode)) return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tabsAndSpaces; Assert.isTrue(false, "Illegal indent mode - must not happen"); // $NON-NLS-1$ return null; }
private void createMessage(final Composite composite) { // TODO create a link with an argument, so the formatter preference page can open the // current profile automatically. String linkTooltip = PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tooltip; String text; String indentMode = JavaPlugin.getDefault() .getCombinedPreferenceStore() .getString(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); if (JavaCore.TAB.equals(indentMode)) text = Messages.format( PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tab_text, new String[] {Integer.toString(getTabDisplaySize())}); else text = Messages.format( PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_others_text, new String[] { Integer.toString(getTabDisplaySize()), Integer.toString(getIndentSize()), getIndentMode() }); final Link link = new Link(composite, SWT.NONE); link.setText(text); link.setToolTipText(linkTooltip); GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gd.widthHint = 300; // don't get wider initially link.setLayoutData(gd); link.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { PreferencesUtil.createPreferenceDialogOn( link.getShell(), "org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage", null, null); //$NON-NLS-1$ } }); final IPreferenceStore combinedStore = JavaPlugin.getDefault().getCombinedPreferenceStore(); final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { private boolean fHasRun = false; public void propertyChange(PropertyChangeEvent event) { if (fHasRun) return; if (composite.isDisposed()) return; String property = event.getProperty(); if (DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR.equals(property) || DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE.equals(property)) { fHasRun = true; link.dispose(); createMessage(composite); Dialog.applyDialogFont(composite); composite.redraw(); composite.layout(); } } }; combinedStore.addPropertyChangeListener(propertyChangeListener); link.addDisposeListener( new DisposeListener() { public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) { combinedStore.removePropertyChangeListener(propertyChangeListener); } }); }