Search in sources :

Example 31 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project linuxtools by eclipse.

the class DockerImagesView method showAllImages.

/**
 * Activates {@link HideDanglingImagesFilter} and
 * {@link HideIntermediateImagesFilter} if the given {@code enabled}
 * argument is <code>false</code>, deactivates the filter otherwise.
 *
 * @param enabled
 *            the argument to enable/disable the filter.
 */
public void showAllImages(boolean enabled) {
    if (!enabled) {
        this.viewer.addFilter(hideDanglingImagesFilter);
        this.viewer.addFilter(hideIntermediateImagesFilter);
    } else {
        final List<ViewerFilter> filters = new ArrayList<>(Arrays.asList(this.viewer.getFilters()));
        // filters
        for (Iterator<ViewerFilter> iterator = filters.iterator(); iterator.hasNext(); ) {
            ViewerFilter viewerFilter = iterator.next();
            if (viewerFilter.equals(hideDanglingImagesFilter) || viewerFilter.equals(hideIntermediateImagesFilter)) {
                iterator.remove();
            }
        }
        this.viewer.setFilters(filters.toArray(new ViewerFilter[0]));
    }
    // Save enablement across sessions using a preference variable.
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    preferences.putBoolean(SHOW_ALL_IMAGES_PREFERENCE, enabled);
    refreshViewTitle();
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ArrayList(java.util.ArrayList)

Example 32 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project linuxtools by eclipse.

the class DockerImagesView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    final FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createForm(parent);
    form.setText(DVMessages.getString(NoConnectionSelected));
    final Composite container = form.getBody();
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(container);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container);
    createTableViewer(container);
    // track selection changes in the Docker Explorer view (only)
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(DockerExplorerView.VIEW_ID, this);
    hookContextMenu();
    // Look at stored preference to determine if all images should be
    // shown or just top-level images. By default, only show
    // top-level images.
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    boolean showAll = preferences.getBoolean(SHOW_ALL_IMAGES_PREFERENCE, false);
    showAllImages(showAll);
    final ICommandService service = getViewSite().getWorkbenchWindow().getService(ICommandService.class);
    service.getCommand(SHOW_ALL_IMAGES_COMMAND_ID).getState(TOGGLE_STATE).setValue(showAll);
    service.refreshElements(SHOW_ALL_IMAGES_COMMAND_ID, null);
    DockerConnectionManager.getInstance().addConnectionManagerListener(this);
    // On startup, this view might get set up after the Docker Explorer View
    // and so we won't get the notification when it chooses the connection.
    // Find out if it has a selection and set our connection appropriately.
    ISelection selection = getSite().getWorkbenchWindow().getSelectionService().getSelection(DockerExplorerView.VIEW_ID);
    if (selection != null) {
        selectionChanged(null, selection);
        // also notify DockerConnectionWatcher
        DockerConnectionWatcher.getInstance().selectionChanged(null, selection);
    }
}
Also used : FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ISelection(org.eclipse.jface.viewers.ISelection) ICommandService(org.eclipse.ui.commands.ICommandService)

Example 33 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project linuxtools by eclipse.

the class ConfigureLabelsPage method setDefaultValues.

private void setDefaultValues() {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    // $NON-NLS-1$
    String filterLabelString = preferences.get(CONTAINER_FILTER_LABELS, "");
    String[] labels = filterLabelString.split("\u00a0");
    LinkedHashMap<String, String> labelMap = new LinkedHashMap<>();
    for (String label : labels) {
        if (label.length() > 1) {
            // $NON-NLS-1$
            String[] tokens = label.split("=");
            String key = tokens[0];
            // $NON-NLS-1$
            String value = "";
            if (tokens.length > 1)
                value = tokens[1];
            labelMap.put(key, value);
        }
    }
    model.setLabelVariables(labelMap);
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) LinkedHashMap(java.util.LinkedHashMap)

Example 34 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project knime-core by knime.

the class ExtensibleUtilityFactoryTest method testGetRendererFamily.

/**
 * Checks if the creation of actual renderer (via the family) works correct.
 */
@Test
public void testGetRendererFamily() {
    DataValueRendererFamily family = StringCell.TYPE.getRenderer(new DataColumnSpecCreator("Test", StringCell.TYPE).createSpec());
    assertThat("Wrong number of renderers in family", family.getRendererDescriptions().length, is(2));
    IEclipsePreferences corePrefs = InstanceScope.INSTANCE.getNode(FrameworkUtil.getBundle(DataValueRendererFactory.class).getSymbolicName());
    DataValueRendererFactory rendererFactory = new DoubleGrayValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(DoubleValue.class), rendererFactory.getId());
    DataColumnSpec colSpec = new DataColumnSpecCreator("Test", DoubleCell.TYPE).createSpec();
    family = DoubleCell.TYPE.getRenderer(colSpec);
    assertThat("Wrong preferred renderer in family list at position 0", family.getRendererDescriptions()[0], is(rendererFactory.createRenderer(colSpec).getDescription()));
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) DoubleValue(org.knime.core.data.DoubleValue) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) Test(org.junit.Test)

Example 35 with IEclipsePreferences

use of org.eclipse.core.runtime.preferences.IEclipsePreferences in project knime-core by knime.

the class ExtensibleUtilityFactoryTest method testPreferredRenderer.

/**
 * Checks if the preferred renderer is correctly read from the preferences.
 */
@Test
public void testPreferredRenderer() {
    ExtensibleUtilityFactory utilityFactory = TestDataValue.UTILITY;
    IEclipsePreferences corePrefs = InstanceScope.INSTANCE.getNode(FrameworkUtil.getBundle(DataValueRendererFactory.class).getSymbolicName());
    DataValueRendererFactory rendererFactory = new TestValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), rendererFactory.getId());
    assertThat("Unexpected preferred renderer", utilityFactory.getPreferredRenderer(), is(rendererFactory));
    rendererFactory = new StringValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), rendererFactory.getId());
    assertThat("Unexpected preferred renderer after preference change", utilityFactory.getPreferredRenderer(), is(rendererFactory));
    DataValueRendererFactory invalidRendererFactory = new MultiLineStringValueRenderer.Factory();
    corePrefs.put(ExtensibleUtilityFactory.getPreferenceKey(TestDataValue.class), invalidRendererFactory.getId());
    assertThat("Unexpected preferred renderer after trying to set invalid preferred renderer", utilityFactory.getPreferredRenderer(), is(IsNull.nullValue()));
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) UtilityFactory(org.knime.core.data.DataValue.UtilityFactory) ExtensibleUtilityFactory(org.knime.core.data.ExtensibleUtilityFactory) Test(org.junit.Test)

Aggregations

IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)79 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Test (org.junit.Test)11 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)9 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)6 ProjectScope (org.eclipse.core.resources.ProjectScope)6 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)6 After (org.junit.After)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)3 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2