Java Code Examples for org.eclipse.ui.editors.text.EditorsUI#getPreferenceStore()

The following examples show how to use org.eclipse.ui.editors.text.EditorsUI#getPreferenceStore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSyntaxColoringPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void dispose() {
	if (fForegroundColor != null) {
		fForegroundColor.dispose();
		fForegroundColor = null;
	}
	if (fBackgroundColor != null) {
		fBackgroundColor.dispose();
		fBackgroundColor = null;
	}
	if (fSelectionForegroundColor != null) {
		fSelectionForegroundColor.dispose();
		fSelectionForegroundColor = null;
	}
	if (fSelectionBackgroundColor != null) {
		fSelectionBackgroundColor.dispose();
		fSelectionBackgroundColor = null;
	}
	if (fListener != null) {
		final IPreferenceStore store = EditorsUI.getPreferenceStore();
		if (store != null) {
			store.removePropertyChangeListener(fListener);
		}
	}
	super.dispose();
}
 
Example 2
Source File: DecoratedScriptEditor.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Constructs a decorated script editor with the specified parent and the
 * specified script.
 * 
 * @param parent
 *            the parent editor.
 * @param script
 *            the script to edit
 */
public DecoratedScriptEditor( IEditorPart parent, String script )
{
	super( );
	this.parent = parent;
	this.sourceViewerConfiguration = new ScriptSourceViewerConfiguration( context );
	setSourceViewerConfiguration( this.sourceViewerConfiguration );
	setDocumentProvider( new ScriptDocumentProvider( parent ) );
	setScript( script );

	IPreferences preferences = PreferenceFactory.getInstance( )
			.getPreferences( ReportPlugin.getDefault( ) );
	if ( preferences instanceof PreferenceWrapper )
	{
		IPreferenceStore store = ( (PreferenceWrapper) preferences ).getPrefsStore( );
		if ( store != null )
		{
			IPreferenceStore baseEditorPrefs = EditorsUI.getPreferenceStore();
			setPreferenceStore( new ChainedPreferenceStore(new IPreferenceStore[]{store, baseEditorPrefs}) );
		}
	}
}
 
Example 3
Source File: AbstractLangBasicSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static final String getAdditionalInfoAffordanceString() {
	IPreferenceStore store = EditorsUI.getPreferenceStore();
	if(!store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE)) {
		return null;
	}
	
	return LangUIMessages.SourceHover_additionalInfo_affordance;
}
 
Example 4
Source File: AbstractSimpleLangSourceViewerConfiguration.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static final String getAdditionalInfoAffordanceString() {
	IPreferenceStore store = EditorsUI.getPreferenceStore();
	if(!store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE)) {
		return null;
	}
	
	return LangUIMessages.SourceHover_additionalInfo_affordance;
}
 
Example 5
Source File: SarosAnnotation.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads the default colors from the plugin.xml and overwrites possible errors in the EditorsUI
 * preference store.
 */
public static void resetColors() {

  log.debug("resetting annotation colors");

  final IPreferenceStore preferenceStore = EditorsUI.getPreferenceStore();

  final AnnotationPreferenceLookup lookup = EditorsUI.getAnnotationPreferenceLookup();

  final String[] annotationTypesToReset = {
    SelectionAnnotation.TYPE, ViewportAnnotation.TYPE, ContributionAnnotation.TYPE
  };

  for (int i = 0; i <= SIZE; ++i) {

    for (String annotationType : annotationTypesToReset) {

      final String annotationTypeToLookup = getNumberedType(annotationType, i);

      final AnnotationPreference preference =
          lookup.getAnnotationPreference(annotationTypeToLookup);

      if (preference == null) {
        log.warn("could not reset color for annotation type: " + annotationTypeToLookup);
        continue;
      }

      preferenceStore.setToDefault(preference.getColorPreferenceKey());

      if (log.isTraceEnabled()) {
        log.trace(
            "reset "
                + annotationTypeToLookup
                + " to: "
                + preferenceStore.getString(preference.getColorPreferenceKey()));
      }
    }
  }
}
 
Example 6
Source File: ToggleLineHighlight.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.EmacsPlusNoEditHandler#transform(ITextEditor, IDocument, ITextSelection, ExecutionEvent)
 */
@Override
protected int transform(ITextEditor editor, IDocument document, ITextSelection currentSelection,
		ExecutionEvent event) throws BadLocationException {
	IPreferenceStore store= EditorsUI.getPreferenceStore();
	if (store != null) {
		store.setValue(EDITOR_CURRENT_LINE, !store.getBoolean(EDITOR_CURRENT_LINE));
	}
	return NO_OFFSET;
}
 
Example 7
Source File: JavaEditorColoringConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private Control createPreviewer(Composite parent) {

		IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
		IPreferenceStore store= new ChainedPreferenceStore(new IPreferenceStore[] { getPreferenceStore(), new PreferencesAdapter(createTemporaryCorePreferenceStore()), generalTextStore });
		fPreviewViewer= new JavaSourceViewer(parent, null, null, false, SWT.H_SCROLL | SWT.BORDER, store);
		SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(fColorManager, store, null, IJavaPartitions.JAVA_PARTITIONING, false);
		fPreviewViewer.configure(configuration);
		// fake 1.5 source to get 1.5 features right.
		configuration.handlePropertyChangeEvent(new PropertyChangeEvent(this, JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4, JavaCore.VERSION_1_5));
		Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
		fPreviewViewer.getTextWidget().setFont(font);
		new JavaSourcePreviewerUpdater(fPreviewViewer, configuration, store);

		fPreviewViewer.setEditable(false);
		Cursor arrowCursor= fPreviewViewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
		fPreviewViewer.getTextWidget().setCursor(arrowCursor);

		// Don't set caret to 'null' as this causes https://bugs.eclipse.org/293263
//		fPreviewViewer.getTextWidget().setCaret(null);

		String content= loadPreviewContentFromFile("ColorSettingPreviewCode.txt"); //$NON-NLS-1$
		IDocument document= new Document(content);
		JavaPlugin.getDefault().getJavaTextTools().setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
		fPreviewViewer.setDocument(document);

		installSemanticHighlighting();


		return fPreviewViewer.getControl();
	}
 
Example 8
Source File: ActionUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isEditable(Shell shell, IJavaElement element) {
	if (! isProcessable(shell, element))
		return false;

	IJavaElement cu= element.getAncestor(IJavaElement.COMPILATION_UNIT);
	if (cu != null) {
		IResource resource= cu.getResource();
		if (resource != null && resource.isDerived(IResource.CHECK_ANCESTORS)) {

			// see org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#validateEditorInputState()
			final String warnKey= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
			IPreferenceStore store= EditorsUI.getPreferenceStore();
			if (!store.getBoolean(warnKey))
				return true;

			MessageDialogWithToggle toggleDialog= MessageDialogWithToggle.openYesNoQuestion(
					shell,
					ActionMessages.ActionUtil_warning_derived_title,
					Messages.format(ActionMessages.ActionUtil_warning_derived_message, BasicElementLabels.getPathLabel(resource.getFullPath(), false)),
					ActionMessages.ActionUtil_warning_derived_dontShowAgain,
					false,
					null,
					null);

			EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());

			return toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
		}
	}
	return true;
}
 
Example 9
Source File: JavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates and returns a preference store which combines the preference
 * stores from the text tools and which is read-only.
 *
 * @param javaTextTools the Java text tools
 * @return the combined read-only preference store
 * @since 3.0
 */
private static final IPreferenceStore createPreferenceStore(JavaTextTools javaTextTools) {
	Assert.isNotNull(javaTextTools);
	IPreferenceStore generalTextStore= EditorsUI.getPreferenceStore();
	if (javaTextTools.getCorePreferenceStore() == null)
		return new ChainedPreferenceStore(new IPreferenceStore[] { javaTextTools.getPreferenceStore(), generalTextStore});

	return new ChainedPreferenceStore(new IPreferenceStore[] { javaTextTools.getPreferenceStore(), new PreferencesAdapter(javaTextTools.getCorePreferenceStore()), generalTextStore });
}
 
Example 10
Source File: AbstractFormatterPreferencePage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param composite
 */
public SourceViewer createSourcePreview(Composite composite, IScriptFormatterFactory factory)
{
	IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
	// TODO - Note that we pass the factory's preferences store and not calling to this.getPrefereceStore.
	// In case we decide to unify the preferences into the this plugin, we might need to change this.
	IPreferenceStore store = new ChainedPreferenceStore(new IPreferenceStore[] { factory.getPreferenceStore(),
			generalTextStore });
	SourceViewer fPreviewViewer = createPreviewViewer(composite, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL
			| SWT.BORDER, store);
	if (fPreviewViewer == null)
	{
		return null;
	}
	SourceViewerConfiguration configuration = (SourceViewerConfiguration) factory
			.createSimpleSourceViewerConfiguration(fColorManager, store, null, false);
	fPreviewViewer.configure(configuration);
	if (fPreviewViewer.getTextWidget().getTabs() == 0)
	{
		fPreviewViewer.getTextWidget().setTabs(4);
	}
	new ScriptSourcePreviewerUpdater(fPreviewViewer, configuration, store);
	fPreviewViewer.setEditable(false);
	IDocument document = new Document();
	fPreviewViewer.setDocument(document);
	IPartitioningConfiguration partitioningConfiguration = (IPartitioningConfiguration) factory
			.getPartitioningConfiguration();
	CompositePartitionScanner partitionScanner = new CompositePartitionScanner(
			partitioningConfiguration.createSubPartitionScanner(), new NullSubPartitionScanner(),
			new NullPartitionerSwitchStrategy());
	IDocumentPartitioner partitioner = new ExtendedFastPartitioner(partitionScanner,
			partitioningConfiguration.getContentTypes());
	partitionScanner.setPartitioner((IExtendedPartitioner) partitioner);
	partitioner.connect(document);
	document.setDocumentPartitioner(partitioner);
	return fPreviewViewer;
}
 
Example 11
Source File: ColorPredicatePreferencePage.java    From tlaplus with MIT License 5 votes vote down vote up
public ColorPredicatePreferencePage()
{
    super(GRID);
    // Using somebody's else PreferenceStore is not a good idea!
    // @see Bug #261 in general/bugzilla/index.html
    final IPreferenceStore[] preferenceStores = new IPreferenceStore[2];
    preferenceStores[0] = EditorsUI.getPreferenceStore();
    preferenceStores[1] = ProverUIActivator.getDefault().getPreferenceStore();
    
    setPreferenceStore(new TLCChainedPreferenceStore(preferenceStores));
    getPreferenceStore().addPropertyChangeListener(this);
    setDescription("Color Predicates");
}
 
Example 12
Source File: TexSourceViewerConfiguration.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new source viewer configuration.
 * 
 * @param te The editor that this configuration is associated to
 */
public TexSourceViewerConfiguration(TexEditor editor) {        
    super(EditorsUI.getPreferenceStore());
    this.editor = editor;
    this.colorManager = new ColorManager();
    this.annotationHover = new TexAnnotationHover();

    // Adds a listener for changing content assistant properties if
    // these are changed in the preferences
    TexlipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new  
            IPropertyChangeListener() {
        
        public void propertyChange(PropertyChangeEvent event) {
            
            if (assistant == null)
                return;
            
            String property = event.getProperty();
            if (TexlipseProperties.TEX_COMPLETION.equals(property)) {
                assistant.enableAutoActivation(
                        TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(
                                TexlipseProperties.TEX_COMPLETION));
            } else if (TexlipseProperties.TEX_COMPLETION_DELAY.equals(property)) {
                assistant.setAutoActivationDelay(
                        TexlipsePlugin.getDefault().getPreferenceStore().getInt(
                                TexlipseProperties.TEX_COMPLETION_DELAY));
            }
        };
    });
    
}
 
Example 13
Source File: PreferenceStoreAccessImpl.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IPreferenceStore getContextPreferenceStore(Object context) {
	lazyInitialize();
	// may be null on shutdown
	Activator activator = Activator.getDefault();
	if (activator != null)
		return new ChainedPreferenceStore(new IPreferenceStore[] { 
				getWritablePreferenceStore(context),
				activator.getPreferenceStore(),
				EditorsUI.getPreferenceStore()});
	return new ChainedPreferenceStore(new IPreferenceStore[] { 
			getWritablePreferenceStore(context),
			EditorsUI.getPreferenceStore()});
}
 
Example 14
Source File: DisableSpellCheckingProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public final void apply(final IDocument document) {
	IPreferenceStore store= EditorsUI.getPreferenceStore();
	store.setValue(SpellingService.PREFERENCE_SPELLING_ENABLED, false);
}
 
Example 15
Source File: TextUMLSourceViewerConfiguration.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
public TextUMLSourceViewerConfiguration(SourceEditor editor) {
    // failing to pass the preference store in causes annotation hovering
    // not to work
    super(EditorsUI.getPreferenceStore());
    this.editor = editor;
}
 
Example 16
Source File: DisableSpellCheckingProposal.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public final void apply(final IDocument document) {
	IPreferenceStore store= EditorsUI.getPreferenceStore();
	store.setValue(SpellingService.PREFERENCE_SPELLING_ENABLED, false);
}
 
Example 17
Source File: AbstractSyntaxColoringPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public AbstractSyntaxColoringPage() {
	final IPreferenceStore store = EditorsUI.getPreferenceStore();
	if (store != null) {
		store.addPropertyChangeListener(fListener);
	}
}
 
Example 18
Source File: AbstractSyntaxColoringPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Initializes the colors of the source preview window based on the values in the Editors' UI preference store
 * 
 * @param viewer the {@link ISourceViewer} used as the source preview
 */
protected void initializeSourcePreviewColors(ISourceViewer viewer) {
	final IPreferenceStore store = EditorsUI.getPreferenceStore();
	if (store != null && viewer != null) {

		final StyledText styledText = viewer.getTextWidget();

		// ----------- foreground color --------------------
		Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay());
		styledText.setForeground(color);

		if (fForegroundColor != null)
			fForegroundColor.dispose();

		fForegroundColor = color;

		// ---------- background color ----------------------
		color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay());
		styledText.setBackground(color);

		if (fBackgroundColor != null)
			fBackgroundColor.dispose();

		fBackgroundColor = color;

		// ----------- selection foreground color --------------------
		color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, styledText.getDisplay());
		styledText.setSelectionForeground(color);

		if (fSelectionForegroundColor != null)
			fSelectionForegroundColor.dispose();

		fSelectionForegroundColor = color;

		// ---------- selection background color ----------------------
		color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, styledText.getDisplay());
		styledText.setSelectionBackground(color);

		if (fSelectionBackgroundColor != null)
			fSelectionBackgroundColor.dispose();

		fSelectionBackgroundColor = color;
	}
}
 
Example 19
Source File: PreferenceStoreAccessor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void populateTextStyle(String id, TextStyle style, TextStyle defaults) {
	IPreferenceStore editorsStore = EditorsUI.getPreferenceStore();
	RGB fontColorDefaultDefault = editorsStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) 
			? getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()
			: PreferenceConverter.getColor(editorsStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);
	RGB backgrounColorDefaultDefault = editorsStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) 
			? getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB() 
			: PreferenceConverter.getColor(editorsStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
	FontData[] fontDataDefaultDefault = JFaceResources.getTextFont().getFontData();

	IPreferenceStore preferenceStore = getPreferenceStore();
	String cssID = CSS_PREFIX + id;
	IPreferenceStore cssPrefStore = getPluginCssPreferenceStore();
	
	String colorKey = PREFERENCE_TAG + getTokenColorPreferenceKey(id);
	String cssFontColor = cssPrefStore.getString(getTokenColorPreferenceKey(cssID));
	if(!Strings.isEmpty(cssFontColor)) {
		preferenceStore.setDefault(colorKey, cssFontColor);
	} else if (defaults.getColor() != null) {
		PreferenceConverter.setDefault(preferenceStore, colorKey, defaults.getColor());
	} else {
		PreferenceConverter.setDefault(preferenceStore, colorKey, fontColorDefaultDefault);
	}
	
	String backgroundKey = PREFERENCE_TAG + getTokenBackgroundColorPreferenceKey(id);
	String cssBgColor = cssPrefStore.getString(getTokenBackgroundColorPreferenceKey(cssID));
	if(!Strings.isEmpty(cssBgColor)) {
		preferenceStore.setDefault(backgroundKey, cssBgColor);
	} else if (defaults.getBackgroundColor() != null) {
		PreferenceConverter.setDefault(preferenceStore, backgroundKey, defaults.getBackgroundColor());
	} else {
		PreferenceConverter.setDefault(preferenceStore, backgroundKey, backgrounColorDefaultDefault);
	}
	
	String fontKey = PREFERENCE_TAG + getTokenFontPreferenceKey(id);
	String cssFont = cssPrefStore.getString(getTokenFontPreferenceKey(cssID));
	if(!Strings.isEmpty(cssFont)) {
		preferenceStore.setDefault(fontKey, cssFont);
	} else if (defaults.getFontData() != null)
		PreferenceConverter.setDefault(preferenceStore, fontKey, defaults.getFontData());
	else {
		PreferenceConverter.setDefault(preferenceStore, fontKey, fontDataDefaultDefault);
	}
	
	String styleKey = PREFERENCE_TAG + getTokenStylePreferenceKey(id);
	int cssStyle = cssPrefStore.getInt(getTokenStylePreferenceKey(cssID));
	if(cssStyle != 0) {
		preferenceStore.setDefault(styleKey, cssStyle);
	} else {
		preferenceStore.setDefault(styleKey, defaults.getStyle());
	}
	
	// populate
	RGB color = PreferenceConverter.getColor(preferenceStore, colorKey);
	if (!color.equals(fontColorDefaultDefault))
		style.setColor(color);
	RGB background = PreferenceConverter.getColor(preferenceStore, backgroundKey);
	if (!background.equals(backgrounColorDefaultDefault))
		style.setBackgroundColor(background);
	FontData[] fontDataArray = PreferenceConverter.getFontDataArray(preferenceStore, fontKey);
	if (!Arrays.equals(fontDataArray, fontDataDefaultDefault)) {
		style.setFontData(fontDataArray);
	}
	style.setStyle(preferenceStore.getInt(styleKey));
}
 
Example 20
Source File: StyledTextDescriptor.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates and returns with a new {@link StyledText styled text} instance hooked up to the given parent composite.
 *
 * @param parent
 *            the parent of the styled text control.
 * @param style
 *            style bits for the new text control.
 * @return a new styled text control initialized from the descriptor.
 */
default StyledText toStyledText(final Composite parent, final int style) {

	final StyledText text = new StyledText(parent, READ_ONLY | style);
	text.setText(getText());
	text.setStyleRanges(getRanges());
	text.setFont(getFont());
	text.setEditable(false);
	text.setEnabled(false);

	final AtomicReference<Color> colorRef = new AtomicReference<>();
	final IPreferenceStore prefStore = EditorsUI.getPreferenceStore();
	if (null == prefStore
			|| prefStore.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {

		colorRef.set(getDefault().getSystemColor(COLOR_LIST_BACKGROUND));

	} else {

		RGB rgb = null;
		if (prefStore.contains(PREFERENCE_COLOR_BACKGROUND)) {
			if (prefStore.isDefault(PREFERENCE_COLOR_BACKGROUND)) {
				rgb = getDefaultColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
			} else {
				rgb = getColor(prefStore, PREFERENCE_COLOR_BACKGROUND);
			}
			if (rgb != null) {
				colorRef.set(new Color(text.getDisplay(), rgb));
			}
		}

	}

	if (null != colorRef.get()) {
		text.setBackground(colorRef.get());
		text.addDisposeListener(e -> {
			if (!colorRef.get().isDisposed()) {
				colorRef.get().dispose();
			}
		});
	}

	text.pack();
	return text;
}