Example usage for org.eclipse.jface.preference IPreferenceStore getInt

List of usage examples for org.eclipse.jface.preference IPreferenceStore getInt

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore getInt.

Prototype

int getInt(String name);

Source Link

Document

Returns the current value of the integer-valued preference with the given name.

Usage

From source file:net.certiv.fluentmark.preferences.OverlayPreferenceStore.java

License:Open Source License

/**
 * Propagates the given overlay key from the origin to the target preference store.
 *
 * @param origin the source preference store
 * @param key the overlay key/*from  w  w w.  j a  va  2  s.  c om*/
 * @param target the preference store to which the key is propagated
 */
private void propagateProperty(IPreferenceStore origin, OverlayKey key, IPreferenceStore target) {

    if (origin.isDefault(key.fKey)) {
        if (!target.isDefault(key.fKey))
            target.setToDefault(key.fKey);
        return;
    }

    TypeDescriptor d = key.fDescriptor;
    if (BOOLEAN == d) {

        boolean originValue = origin.getBoolean(key.fKey);
        boolean targetValue = target.getBoolean(key.fKey);
        if (targetValue != originValue)
            target.setValue(key.fKey, originValue);

    } else if (DOUBLE == d) {

        double originValue = origin.getDouble(key.fKey);
        double targetValue = target.getDouble(key.fKey);
        if (targetValue != originValue)
            target.setValue(key.fKey, originValue);

    } else if (FLOAT == d) {

        float originValue = origin.getFloat(key.fKey);
        float targetValue = target.getFloat(key.fKey);
        if (targetValue != originValue)
            target.setValue(key.fKey, originValue);

    } else if (INT == d) {

        int originValue = origin.getInt(key.fKey);
        int targetValue = target.getInt(key.fKey);
        if (targetValue != originValue)
            target.setValue(key.fKey, originValue);

    } else if (LONG == d) {

        long originValue = origin.getLong(key.fKey);
        long targetValue = target.getLong(key.fKey);
        if (targetValue != originValue)
            target.setValue(key.fKey, originValue);

    } else if (STRING == d) {

        String originValue = origin.getString(key.fKey);
        String targetValue = target.getString(key.fKey);
        if (targetValue != null && originValue != null && !targetValue.equals(originValue))
            target.setValue(key.fKey, originValue);

    }
}

From source file:net.certiv.fluentmark.preferences.OverlayPreferenceStore.java

License:Open Source License

/**
 * Loads the given key from the origin into the target.
 *
 * @param origin the source preference store
 * @param key the overlay key//  ww  w. j  av a  2 s .c om
 * @param target the preference store to which the key is propagated
 * @param forceInitialization if <code>true</code> the value in the target gets initialized
 *            before loading
 */
private void loadProperty(IPreferenceStore origin, OverlayKey key, IPreferenceStore target,
        boolean forceInitialization) {
    TypeDescriptor d = key.fDescriptor;
    if (BOOLEAN == d) {

        if (forceInitialization)
            target.setValue(key.fKey, true);
        target.setValue(key.fKey, origin.getBoolean(key.fKey));
        target.setDefault(key.fKey, origin.getDefaultBoolean(key.fKey));

    } else if (DOUBLE == d) {

        if (forceInitialization)
            target.setValue(key.fKey, 1.0D);
        target.setValue(key.fKey, origin.getDouble(key.fKey));
        target.setDefault(key.fKey, origin.getDefaultDouble(key.fKey));

    } else if (FLOAT == d) {

        if (forceInitialization)
            target.setValue(key.fKey, 1.0F);
        target.setValue(key.fKey, origin.getFloat(key.fKey));
        target.setDefault(key.fKey, origin.getDefaultFloat(key.fKey));

    } else if (INT == d) {

        if (forceInitialization)
            target.setValue(key.fKey, 1);
        target.setValue(key.fKey, origin.getInt(key.fKey));
        target.setDefault(key.fKey, origin.getDefaultInt(key.fKey));

    } else if (LONG == d) {

        if (forceInitialization)
            target.setValue(key.fKey, 1L);
        target.setValue(key.fKey, origin.getLong(key.fKey));
        target.setDefault(key.fKey, origin.getDefaultLong(key.fKey));

    } else if (STRING == d) {

        if (forceInitialization)
            target.setValue(key.fKey, "1"); //$NON-NLS-1$
        target.setValue(key.fKey, origin.getString(key.fKey));
        target.setDefault(key.fKey, origin.getDefaultString(key.fKey));

    }
}

From source file:net.jmesnil.jmx.ui.internal.views.explorer.MBeanExplorer.java

License:Open Source License

private void restoreLayoutState(IMemento memento) {
    Integer state = null;//from w  w w  . j a v a 2 s.  co  m
    if (memento != null)
        state = memento.getInteger(TAG_LAYOUT);

    // If no memento try an restore from preference store
    if (state == null) {
        IPreferenceStore store = JMXUIActivator.getDefault().getPreferenceStore();
        state = new Integer(store.getInt(TAG_LAYOUT));
    }

    if (state.intValue() == FLAT_LAYOUT)
        currentLayoutIsFlat = true;
    else if (state.intValue() == HIERARCHICAL_LAYOUT)
        currentLayoutIsFlat = false;
    else
        currentLayoutIsFlat = false;
}

From source file:net.jmesnil.jmx.ui.internal.views.explorer.MBeanExplorer.java

License:Open Source License

private void restoreLinkWithEditorState(IMemento memento) {
    Integer state = null;/*from w ww .j av  a2s.co m*/
    if (memento != null)
        state = memento.getInteger(TAG_LINKED_WITH_EDITOR);

    // If no memento try an restore from preference store
    if (state == null) {
        IPreferenceStore store = JMXUIActivator.getDefault().getPreferenceStore();
        state = new Integer(store.getInt(TAG_LINKED_WITH_EDITOR));
    }

    if (state.intValue() == 0)
        linkingIsEnabled = true;
    else if (state.intValue() == 1)
        linkingIsEnabled = false;
    else
        linkingIsEnabled = false;
}

From source file:net.openchrom.xxd.processor.supplier.rscripting.ui.jobs.TransferDataframeToGridJob.java

License:Open Source License

public static void transferWithHead(boolean head, String name) {

    RConnection c = RServe.getConnection();
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    boolean format = store.getBoolean("TRANSFER_METHOD");
    int digits = store.getInt("DEFAULT_DIGITS");
    String[] matrix = null;//from w w  w. j  a  v  a2  s  . c o  m
    boolean withHead = head;
    int lengthY = 0;
    int lengthX = 0;
    try {
        lengthY = c.eval("try(length(" + name + "[,1]))").asInteger();
        lengthX = c.eval("try(length(" + name + "[1,]))").asInteger();
    } catch (REXPMismatchException e) {
        e.printStackTrace();
    } catch (RserveException e) {
        e.printStackTrace();
    }
    Grid grid = SampleView.getGrid();
    grid = new Spread().spread(SampleView.getTabFolder(), lengthX, lengthY, name);
    SampleView.setGrid(grid);
    if (grid != null) {
        int colCount = grid.getColumnCount();
        int rowCount = grid.getItemCount();
        if (colCount < lengthX) {
            int diff = lengthX - colCount;
            for (int i = 0; i < diff; i++) {
                GridColumn column = new GridColumn(grid, SWT.NONE);
                column.setText("C " + (i + 1 + colCount));
                column.setWidth(50);
            }
        }
        if (rowCount < lengthY) {
            int diff = lengthY - rowCount;
            for (int i = 0; i < diff; i++) {
                new GridItem(grid, SWT.NONE);
            }
        }
        if (withHead == false) {
            for (int j = 0; j < lengthX; j++) {
                try {
                    // Get the columns!
                    if (format) {
                        matrix = c.eval(
                                "try(format(" + name + "[," + (j + 1) + "],trim = TRUE,digits=" + digits + "))")
                                .asStrings();
                    } else {
                        matrix = c.eval("try(as.character(" + name + "[," + (j + 1) + "]))").asStrings();
                    }
                } catch (REXPMismatchException e) {
                    e.printStackTrace();
                } catch (RserveException e) {
                    e.printStackTrace();
                }
                String value;
                for (int k = 0; k < lengthY; k++) {
                    if (matrix[k] == null) {
                        value = "NA";
                    } else {
                        value = matrix[k].toString();
                    }
                    grid.getItem(k).setText(j, value);
                }
            }
        } else {
            String[] names = null;
            try {
                names = c.eval("try(names(" + name + "))").asStrings();
            } catch (REXPMismatchException e1) {
                e1.printStackTrace();
            } catch (RserveException e1) {
                e1.printStackTrace();
            }
            // Add additional item for the head!
            new GridItem(grid, SWT.NONE);
            for (int j = 0; j < lengthX; j++) {
                try {
                    // Get the columns!
                    if (format) {
                        matrix = c.eval(
                                "try(format(" + name + "[," + (j + 1) + "],trim = TRUE,digits=" + digits + "))")
                                .asStrings();
                    } else {
                        matrix = c.eval("try(as.character(" + name + "[," + (j + 1) + "]))").asStrings();
                    }
                } catch (REXPMismatchException e) {
                    e.printStackTrace();
                } catch (RserveException e) {
                    e.printStackTrace();
                }
                String value;
                for (int k = 0; k < lengthY + 1; k++) {
                    if (k > 0) {
                        if (matrix[k - 1] == null) {
                            value = "NA";
                        } else {
                            value = matrix[k - 1].toString();
                        }
                        grid.getItem(k).setText(j, value);
                    } else {
                        grid.getItem(k).setText(j, names[j]);
                    }
                }
            }
        }
    }
}

From source file:net.refractions.udig.printing.ui.internal.editor.PageEditor.java

License:Open Source License

@Override
public void dispose() {

    if (PlatformUI.getWorkbench().isClosing()) {
        ProjectPlugin.getPlugin().turnOffEvents();

        // save the map's URI in the preferences so that it will be loaded the next time udig is
        // run.//w w  w  . ja v  a2 s  .c om

        Resource resource = this.page.eResource();
        if (resource != null) {
            try {
                IPreferenceStore p = ProjectUIPlugin.getDefault().getPreferenceStore();
                int numEditors = p.getInt(ID);
                String id = ID + ":" + numEditors; //$NON-NLS-1$
                numEditors++;
                p.setValue(ID, numEditors);
                String value = resource.getURI().toString();
                p.setValue(id, value);
            } catch (Exception e) {
                ProjectUIPlugin.log("Failure saving which maps are open", e); //$NON-NLS-1$
            }
        }
    }

    try {
        getSite().getWorkbenchWindow().run(false, false, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                Project p = page.getProjectInternal();
                try {
                    if (p != null) {
                        if (p.eResource() != null && p.eResource().isModified()) {
                            p.eResource().save(ProjectPlugin.getPlugin().saveOptions);
                        }
                        saveAndUnload();
                    } else {
                        saveAndUnload();
                    }
                } catch (IOException e) {
                    ProjectPlugin.log("", e); //$NON-NLS-1$
                }

                // need to kick the Project so viewers will update
                p.eNotify(new ENotificationImpl((InternalEObject) p, Notification.SET,
                        ProjectPackage.PROJECT__ELEMENTS_INTERNAL, null, null));
            }

            private void saveAndUnload() throws IOException {
                final Resource resource = page.eResource();

                resource.save(ProjectPlugin.getPlugin().saveOptions);
                if (!resource.getContents().contains(ProjectPlugin.getPlugin().getProjectRegistry()))
                    ;
                resource.unload();
            }
        });
    } catch (Exception e) {
        ProjectPlugin.log("", e); //$NON-NLS-1$
    }
    super.dispose();
}

From source file:net.refractions.udig.project.ui.internal.ProjectUIPlugin.java

License:Open Source License

/**
 * The delay used to determine double click speed.
 * /*  ww w .j  av a 2 s. co  m*/
 * <p>
 * The delay defaults to 100 milliseconds.
 * </p>
 * 
 * @return the milliseconds used for the double-click speed.
 */
public int getDoubleClickSpeed() {
    IPreferenceStore store = ProjectUIPlugin.getDefault().getPreferenceStore();
    int mouseSpeed = store.getInt(MOUSE_SPEED_KEY);
    if (mouseSpeed == 0) {
        mouseSpeed = DEFAULT_DOUBLECLICK_SPEED_MILLIS;
    }
    return mouseSpeed;
}

From source file:net.rim.ejde.internal.ui.views.profiler.ProfilerView.java

License:Open Source License

/**
 * Initializes all parameters related to profile.
 *
 * @throws CoreException//w  ww  .  j a  va 2  s.c o  m
 *
 */
private void initProfileParameters(RIA ria) {
    if (ria != null) {
        if (!DebugUtils.isRIMDebuggerRunning()) {
            return;
        }
        if (!ria.getProfileEnabled()) {
            ria.setProfileEnabled(true);
        }
        cleanMessage();
        try {
            // get profile options from preference store
            IPreferenceStore ps = ContextManager.PLUGIN.getPreferenceStore();
            _whatToProfile = ps.getInt(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_WHATTOPROFILE);
            ProfileType[] types;
            // MKS 2486071
            String debugAttachedTo = ria.getDebugAttachTo();
            if (debugAttachedTo == null || debugAttachedTo.isEmpty()) {
                return;
            } else {
                types = ProfilingViewOptionsDialog.getProfileTypes(ria);
            }

            if (!isValidProfileId(types, _whatToProfile)) {
                _whatToProfile = types[0].getId();
            }
            _methodTimeType = ps.getBoolean(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_METHOD_TIME_TYPE);
            log.debug("Profile option - type:" + _whatToProfile + ", method: "
                    + (_methodTimeType ? "Cumulative" : "In method only"));
            ria.profileSetType(_whatToProfile);
            updateTypeColumeTitle();
            _isInitialized = true;
        } catch (Exception e) {
            log.error("", e);
        }
    }
}

From source file:net.rim.ejde.internal.ui.views.profiler.ProfilerView.java

License:Open Source License

/**
 * Opens an option dialog. Options related to profiler can be set on the dialog and will be saved as references when "OK"
 * button is pressed.//from  w  w  w  .j  a v  a 2  s. co m
 *
 * @see BasicDebugView#setOptions().
 */
public void setOptions() {
    // create an ImplicitBuildRuleEditDialog instance
    ProfilingViewOptionsDialog optionsDialog = new ProfilingViewOptionsDialog(getSite().getShell());
    // show the dialog
    optionsDialog.open();
    if (optionsDialog.isOkButtonClicked()) {
        try {
            IPreferenceStore ps = ContextManager.PLUGIN.getPreferenceStore();
            int whatToProfile = ps.getInt(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_WHATTOPROFILE);
            if (whatToProfile != _whatToProfile) {
                initProfileParameters(RIA.getCurrentDebugger());
                clear();
                enableActions(REFRESH_BUTTON, false);
            } else {
                initProfileParameters(RIA.getCurrentDebugger());
                refresh(false);
            }
        } catch (Exception e) {
            log.error("", e);
        }
    }
}

From source file:net.rim.ejde.internal.ui.views.profiler.ProfilingViewOptionsDialog.java

License:Open Source License

/**
 * Creates the dialog's contents// w w  w  .  j a v a  2 s.  c  o m
 *
 * @param shell
 *            the dialog window
 */
private void createContents(final Shell shell) {
    IPreferenceStore ps = ContextManager.PLUGIN.getPreferenceStore();
    shell.setLayout(new GridLayout(2, false));
    GridData data;
    data = new GridData(GridData.FILL_HORIZONTAL);
    // Display the "method attribution" combo
    Label label1 = new Label(shell, SWT.NONE);
    label1.setText(Messages.OptionsDialog_METHOD_ATTRIBUTION_LABEL_TITLE);
    final Combo comMethodAtt = new Combo(shell, SWT.READ_ONLY);
    comMethodAtt.setLayoutData(data);
    comMethodAtt.setItems(
            new String[] { RIA.getString(Messages.OptionsDialog_1), RIA.getString(Messages.OptionsDialog_2) });
    comMethodAtt.select(ps.getBoolean(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_METHOD_TIME_TYPE) ? 0 : 1);

    // Display the "what to profile" combo
    Label label2 = new Label(shell, SWT.NONE);
    label2.setText(Messages.OptionsDialog_WHATTOPROFILE_LABEL_TITLE);
    final Combo comWhatToProfile = new Combo(shell, SWT.READ_ONLY);
    comWhatToProfile.setLayoutData(data);
    comWhatToProfile.setItems(getProfileTypeNames());
    comWhatToProfile.select(
            indexOfProfileType(types, ps.getInt(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_WHATTOPROFILE)));

    Composite buttonComposite = new Composite(shell, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttonComposite.setLayout(layout);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    buttonComposite.setLayoutData(data);

    // Create the OK button and add a handler
    // so that pressing it will set input
    // to the entered value
    Button ok = new Button(buttonComposite, SWT.PUSH);
    ok.setText(Messages.IConstants_OK_BUTTON_TITLE);
    data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END);
    data.widthHint = 60;
    ok.setLayoutData(data);
    ok.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            _okButtonClicked = true;
            IPreferenceStore preferenceStore = ContextManager.PLUGIN.getPreferenceStore();
            preferenceStore.setValue(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_WHATTOPROFILE,
                    types[comWhatToProfile.getSelectionIndex()].getId());
            preferenceStore.setValue(PreferenceConstants.NET_RIM_EJDE_UI_VIEWS_METHOD_TIME_TYPE,
                    comMethodAtt.getSelectionIndex() == 0 ? true : false);
            shell.close();
        }
    });

    // Create the cancel button and add a handler
    Button cancel = new Button(buttonComposite, SWT.PUSH);
    cancel.setText(Messages.IConstants_CANCEL_BUTTON_TITLE);
    data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
    data.widthHint = 60;
    cancel.setLayoutData(data);
    cancel.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            _okButtonClicked = false;
            shell.close();
        }
    });

    // Set the OK button as the default, so
    // user can type input and press Enter
    // to dismiss
    shell.setDefaultButton(ok);
}