Search in sources :

Example 1 with ColorDefinition

use of org.eclipse.ui.internal.themes.ColorDefinition in project archi by archimatetool.

the class PaletteColorUtil method getThemeColor.

/**
 * Added by Phillipus - get a theme color from the theme registry
 */
private static Color getThemeColor(final String id, RGB defaultColor) {
    IThemeRegistry reg = WorkbenchPlugin.getDefault().getThemeRegistry();
    ColorDefinition colorDef = reg.findColor(id);
    if (colorDef != null && colorDef.getValue() != null) {
        defaultColor = colorDef.getValue();
    }
    return new Color(defaultColor);
}
Also used : IThemeRegistry(org.eclipse.ui.internal.themes.IThemeRegistry) ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) Color(org.eclipse.swt.graphics.Color)

Example 2 with ColorDefinition

use of org.eclipse.ui.internal.themes.ColorDefinition in project eclipse.platform.ui by eclipse-platform.

the class ColorDefinitionTest method testColorDefinitionWhenNameCategoryIdAndDescriptionOverridden.

@Test
public void testColorDefinitionWhenNameCategoryIdAndDescriptionOverridden() {
    // given
    CSSEngine engine = createEngine("ColorDefinition#ACTIVE_HYPERLINK_COLOR{color: green;" + "label:'nameOverridden'; category:'#categoryIdOverridden'; description: 'descriptionOverridden'}", display);
    ColorDefinition definition = colorDefinition("ACTIVE_HYPERLINK_COLOR", "name", "categoryId", "description");
    assertEquals(new RGB(0, 0, 0), definition.getValue());
    assertFalse(definition.isOverridden());
    // when
    engine.applyStyles(definition, true);
    // then
    assertEquals(new RGB(0, 128, 0), definition.getValue());
    assertEquals("nameOverridden", definition.getName());
    assertEquals("categoryIdOverridden", definition.getCategoryId());
    assertTrue(definition.getDescription().startsWith("descriptionOverridden"));
    assertTrue(definition.isOverridden());
    engine.dispose();
}
Also used : ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) CSSEngine(org.eclipse.e4.ui.css.core.engine.CSSEngine) RGB(org.eclipse.swt.graphics.RGB) Test(org.junit.Test)

Example 3 with ColorDefinition

use of org.eclipse.ui.internal.themes.ColorDefinition in project eclipse.platform.ui by eclipse-platform.

the class PluginContributionAdapterFactory method getAdapter.

@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType != ContributionInfo.class) {
        return null;
    }
    if (adaptableObject instanceof IPluginContribution) {
        IPluginContribution contribution = (IPluginContribution) adaptableObject;
        String elementType;
        if (contribution instanceof EditorDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_Editor;
        } else if (contribution instanceof ViewDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_View;
        } else if (contribution instanceof ActionSetDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_ActionSet;
        } else if (contribution instanceof Category) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof IViewCategory) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof ThemeElementCategory) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof WizardCollectionElement) {
            elementType = ContributionInfoMessages.ContributionInfo_Category;
        } else if (contribution instanceof ColorDefinition) {
            elementType = ContributionInfoMessages.ContributionInfo_ColorDefinition;
        } else if (contribution instanceof WorkbenchWizardElement) {
            elementType = ContributionInfoMessages.ContributionInfo_Wizard;
        } else if (contribution instanceof PerspectiveDescriptor) {
            elementType = ContributionInfoMessages.ContributionInfo_Perspective;
        } else if (contribution instanceof WorkbenchPreferenceExpressionNode) {
            elementType = ContributionInfoMessages.ContributionInfo_Page;
        } else if (contribution instanceof DecoratorDefinition) {
            elementType = ContributionInfoMessages.ContributionInfo_LabelDecoration;
        } else {
            elementType = ContributionInfoMessages.ContributionInfo_Unknown;
        }
        return adapterType.cast(new ContributionInfo(contribution.getPluginId(), elementType, null));
    }
    if (adaptableObject instanceof JobInfo) {
        JobInfo jobInfo = (JobInfo) adaptableObject;
        Job job = jobInfo.getJob();
        if (job != null) {
            Bundle bundle = FrameworkUtil.getBundle(job.getClass());
            if (bundle != null) {
                return adapterType.cast(new ContributionInfo(bundle.getSymbolicName(), ContributionInfoMessages.ContributionInfo_Job, null));
            }
        }
    }
    return null;
}
Also used : ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) IViewCategory(org.eclipse.ui.views.IViewCategory) Category(org.eclipse.ui.internal.registry.Category) ThemeElementCategory(org.eclipse.ui.internal.themes.ThemeElementCategory) ThemeElementCategory(org.eclipse.ui.internal.themes.ThemeElementCategory) WorkbenchPreferenceExpressionNode(org.eclipse.ui.internal.preferences.WorkbenchPreferenceExpressionNode) ContributionInfo(org.eclipse.ui.testing.ContributionInfo) Bundle(org.osgi.framework.Bundle) ActionSetDescriptor(org.eclipse.ui.internal.registry.ActionSetDescriptor) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) ViewDescriptor(org.eclipse.ui.internal.registry.ViewDescriptor) IViewCategory(org.eclipse.ui.views.IViewCategory) JobInfo(org.eclipse.ui.internal.progress.JobInfo) IPluginContribution(org.eclipse.ui.IPluginContribution) WizardCollectionElement(org.eclipse.ui.internal.dialogs.WizardCollectionElement) WorkbenchWizardElement(org.eclipse.ui.internal.dialogs.WorkbenchWizardElement) DecoratorDefinition(org.eclipse.ui.internal.decorators.DecoratorDefinition) Job(org.eclipse.core.runtime.jobs.Job) PerspectiveDescriptor(org.eclipse.ui.internal.registry.PerspectiveDescriptor)

Example 4 with ColorDefinition

use of org.eclipse.ui.internal.themes.ColorDefinition in project eclipse.platform.ui by eclipse-platform.

the class ExtensionEventHandler method loadThemes.

// TODO: confirm
private void loadThemes(IExtension ext) {
    ThemeRegistryReader reader = new ThemeRegistryReader();
    ThemeRegistry registry = (ThemeRegistry) WorkbenchPlugin.getDefault().getThemeRegistry();
    reader.setRegistry(registry);
    for (IConfigurationElement configElement : ext.getConfigurationElements()) {
        reader.readElement(configElement);
    }
    Collection<ColorDefinition> colors = reader.getColorDefinitions();
    ColorDefinition[] colorDefs = colors.toArray(new ColorDefinition[colors.size()]);
    ITheme theme = workbench.getThemeManager().getTheme(IThemeManager.DEFAULT_THEME);
    ThemeElementHelper.populateRegistry(theme, colorDefs, PrefUtil.getInternalPreferenceStore());
    Collection<FontDefinition> fonts = reader.getFontDefinitions();
    FontDefinition[] fontDefs = fonts.toArray(new FontDefinition[fonts.size()]);
    ThemeElementHelper.populateRegistry(theme, fontDefs, PrefUtil.getInternalPreferenceStore());
    Map<String, String> data = reader.getData();
    registry.addData(data);
}
Also used : ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) ITheme(org.eclipse.ui.themes.ITheme) FontDefinition(org.eclipse.ui.internal.themes.FontDefinition) ThemeRegistry(org.eclipse.ui.internal.themes.ThemeRegistry) ThemeRegistryReader(org.eclipse.ui.internal.themes.ThemeRegistryReader) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 5 with ColorDefinition

use of org.eclipse.ui.internal.themes.ColorDefinition in project eclipse.platform.ui by eclipse-platform.

the class ThemesExtensionTest method testThemesExtension.

@Test
public void testThemesExtension() {
    // given
    engine = createEngine("ThemesExtension {font-definition: '#org-eclipse-ui-workbench-FONT_DEF_1'," + "'#org-eclipse-ui-workbench-FONT_DEF_2'; color-definition: '#org-eclipse-ui-workbench-COLOR_DEF_1';}", display);
    ThemesExtension themesExtention = new ThemesExtension();
    // when
    engine.applyStyles(themesExtention, true);
    // then
    assertEquals(3, themesExtention.getDefinitions().size());
    assertTrue(themesExtention.getDefinitions().get(0) instanceof FontDefinition);
    FontDefinition fontDefinition1 = (FontDefinition) themesExtention.getDefinitions().get(0);
    assertTrue(fontDefinition1.isAddedByCss());
    assertFalse(fontDefinition1.isOverridden());
    assertEquals("org.eclipse.ui.workbench.FONT_DEF_1", fontDefinition1.getId());
    assertEquals(ThemesExtension.DEFAULT_CATEGORY_ID, fontDefinition1.getCategoryId());
    assertTrue(fontDefinition1.getName().startsWith(FontDefinition.class.getSimpleName()));
    assertTrue(fontDefinition1.getName().endsWith(fontDefinition1.getId()));
    assertNotNull(fontDefinition1.getDescription());
    assertTrue(themesExtention.getDefinitions().get(1) instanceof FontDefinition);
    FontDefinition fontDefinition2 = (FontDefinition) themesExtention.getDefinitions().get(1);
    assertTrue(fontDefinition2.isAddedByCss());
    assertFalse(fontDefinition2.isOverridden());
    assertEquals("org.eclipse.ui.workbench.FONT_DEF_2", fontDefinition2.getId());
    assertEquals(ThemesExtension.DEFAULT_CATEGORY_ID, fontDefinition1.getCategoryId());
    assertTrue(fontDefinition2.getName().startsWith(FontDefinition.class.getSimpleName()));
    assertTrue(fontDefinition2.getName().endsWith(fontDefinition2.getId()));
    assertNotNull(fontDefinition2.getDescription());
    assertTrue(themesExtention.getDefinitions().get(2) instanceof ColorDefinition);
    ColorDefinition colorDefinition1 = (ColorDefinition) themesExtention.getDefinitions().get(2);
    assertTrue(colorDefinition1.isAddedByCss());
    assertFalse(colorDefinition1.isOverridden());
    assertEquals("org.eclipse.ui.workbench.COLOR_DEF_1", colorDefinition1.getId());
    assertNotNull(colorDefinition1.getDescription());
    assertEquals(ThemesExtension.DEFAULT_CATEGORY_ID, colorDefinition1.getCategoryId());
    assertTrue(colorDefinition1.getName().startsWith(ColorDefinition.class.getSimpleName()));
    assertTrue(colorDefinition1.getName().endsWith(colorDefinition1.getId()));
    assertNotNull(colorDefinition1.getDescription());
}
Also used : ThemesExtension(org.eclipse.ui.internal.themes.ThemesExtension) ColorDefinition(org.eclipse.ui.internal.themes.ColorDefinition) FontDefinition(org.eclipse.ui.internal.themes.FontDefinition) Test(org.junit.Test)

Aggregations

ColorDefinition (org.eclipse.ui.internal.themes.ColorDefinition)15 Test (org.junit.Test)12 FontDefinition (org.eclipse.ui.internal.themes.FontDefinition)9 RGB (org.eclipse.swt.graphics.RGB)8 ThemeRegistry (org.eclipse.ui.internal.themes.ThemeRegistry)8 ColorRegistry (org.eclipse.jface.resource.ColorRegistry)7 FontRegistry (org.eclipse.jface.resource.FontRegistry)7 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)5 ThemesExtension (org.eclipse.ui.internal.themes.ThemesExtension)5 Event (org.osgi.service.event.Event)5 CSSEngine (org.eclipse.e4.ui.css.core.engine.CSSEngine)4 IStylingEngine (org.eclipse.e4.ui.services.IStylingEngine)4 ITheme (org.eclipse.ui.themes.ITheme)3 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 Job (org.eclipse.core.runtime.jobs.Job)1 ITheme (org.eclipse.e4.ui.css.swt.theme.ITheme)1 Color (org.eclipse.swt.graphics.Color)1 FontData (org.eclipse.swt.graphics.FontData)1 IPluginContribution (org.eclipse.ui.IPluginContribution)1 DecoratorDefinition (org.eclipse.ui.internal.decorators.DecoratorDefinition)1