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

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

Introduction

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

Prototype

boolean getBoolean(String name);

Source Link

Document

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

Usage

From source file:com.subgraph.vega.ui.scanner.ScanExecutor.java

License:Open Source License

private String maybeLaunchScanFromWizard(Shell shell, NewScanWizard wizard, IScanner scanner) {
    URI targetURI = wizard.getScanHostURI();
    if (targetURI == null) {
        return null;
    }// w  ww .j ava2  s.com
    scanner.lock();
    final IScannerConfig config = scanner.createScannerConfig();

    config.setBaseURI(targetURI);
    config.setCookieList(getCookieList(wizard.getCookieStringList(), targetURI));
    config.setBasicUsername(wizard.getBasicUsername());
    config.setBasicPassword(wizard.getBasicPassword());
    config.setBasicRealm(wizard.getBasicRealm());
    config.setBasicDomain(wizard.getBasicDomain());
    config.setExclusions(wizard.getExclusions());
    config.setNtlmUsername(wizard.getNtlmUsername());
    config.setNtlmPassword(wizard.getNtlmPassword());
    final IPreferenceStore preferences = Activator.getDefault().getPreferenceStore();
    config.setLogAllRequests(preferences.getBoolean("LogAllRequests"));
    config.setDisplayDebugOutput(preferences.getBoolean("DisplayDebugOutput"));
    config.setMaxRequestsPerSecond(preferences.getInt("MaxRequestsPerSecond"));
    config.setMaxDescendants(preferences.getInt("MaxScanDescendants"));
    config.setMaxChildren(preferences.getInt("MaxScanChildren"));
    config.setMaxDepth(preferences.getInt("MaxScanDepth"));
    config.setMaxDuplicatePaths(preferences.getInt("MaxScanDuplicatePaths"));
    config.setMaxResponseKilobytes(preferences.getInt("MaxResponseLength"));

    final Thread probeThread = new Thread(new ScanProbeTask(shell, targetURI, scanner, config));
    probeThread.start();
    return wizard.getTargetField();
}

From source file:com.sureassert.uc.SaUCPreferencePage.java

License:Open Source License

/**
 * Initializes states of the controls from the preference store.
 */// w  w  w. ja  v  a2s .c  om
private void initializeValues() {

    IPreferenceStore store = getPreferenceStore();
    SaUCPreferences.setDefaults(store);
    runJunitAutomaticallyCheckbox.setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_JUNIT_AUTOMATION));
    junitExcludeFilterText.setText(store.getString(SaUCPreferences.PREF_KEY_JUNIT_EXCLUDE_FILTER));
    calculateCoverageCheckbox.setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_COVERAGE_ENABLED));
    coverageProblemsCheckbox.setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_COVERAGE_PROBLEMS_ENABLED));
    coverageProjectDecorationCheckbox
            .setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_COVERAGE_PROJECT_DECORATION_ENABLED));
    coverageFileDecorationCheckbox
            .setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_COVERAGE_FILE_DECORATION_ENABLED));
    coverageFilePercentCheckbox
            .setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_COVERAGE_FILE_PERCENT_ENABLED));
    coverageDisplayEnabledCheckbox
            .setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_COVERAGE_DISPLAY_ENABLED));
    coverageWarnThreshold.setSelection(store.getInt(SaUCPreferences.PREF_KEY_COVERAGE_WARN_THRESHOLD));
    coverageErrorThreshold.setSelection(store.getInt(SaUCPreferences.PREF_KEY_COVERAGE_ERROR_THRESHOLD));
    // coverageRequiredThreshold.setSelection(store.getInt(SaUCPreferences.PREF_KEY_COVERAGE_REQUIRED_THRESHOLD));
    sourceStubsEnabledCheckbox
            .setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_STUBS_ALLOW_SOURCE_STUBS));
    // licenceKeyText.setText(store.getString(SaUCPreferences.PREF_KEY_LICENCE_KEY));
    // licenceEmailText.setText(store.getString(SaUCPreferences.PREF_KEY_LICENCE_EMAIL));
    // execConcurrentCheckbox.setSelection(store.getBoolean(SaUCPreferences.PREF_KEY_EXEC_CONCURRENT));

    rationalizeControls();
}

From source file:com.telink.tc32eclipse.core.toolinfo.FindTCDB.java

License:Open Source License

/**
 * Runs TCDB with the given arguments./*from  w  ww .  j a va 2  s.c  om*/
 * <p>
 * The Output of stdout and stderr are merged and returned in a <code>List&lt;String&gt;</code>.
 * If the "use Console" flag is set in the Preferences, the complete output is shown on a
 * Console as well.
 * </p>
 * <p>
 * If the command fails to execute an entry is written to the log and an
 * {@link TCDBException} with the reason is thrown.
 * </p>
 * 
 * @param arguments
 *            <code>List&lt;String&gt;</code> with the arguments
 * @param monitor
 *            <code>IProgressMonitor</code> to cancel the running process.
 * @param forceconsole
 *            If <code>true</code> all output is copied to the console, regardless of the "use
 *            console" flag.
 * @param cwd
 *            <code>IPath</code> with a current working directory or <code>null</code> to use
 *            the default working directory (usually the one defined with the system property
 *            <code>user.dir</code). May not be empty.
 * @param programmerconfig
 *            The TCDB Programmer configuration currently is use. Required for the TCDB
 *            invocation delay value. If <code>null</code> no invocation delay will be done.
 * @return A list of all output lines, or <code>null</code> if the command could not be
 *         launched.
 * @throws TCDBException
 *             when TCDB cannot be started or when TCDB returned an error errors.
 */
public List<String> runCommand(List<String> arglist, IProgressMonitor monitor, boolean forceconsole, IPath cwd,
        ProgrammerConfig programmerconfig) throws TCDBException {

    try {
        monitor.beginTask("Running TCDB", 100);

        // Check if the CWD is valid
        if (cwd != null && cwd.isEmpty()) {
            throw new TCDBException(Reason.INVALID_CWD, "CWD does not point to a valid directory.");
        }

        // PS String command = getToolFullPath().toOSString();
        String command = getToolFullPath().toPortableString();

        // Check if the user has a custom configuration file
        IPreferenceStore TCDBprefs = TCDBPreferences.getPreferenceStore();
        boolean usecustomconfig = TCDBprefs.getBoolean(TCDBPreferences.KEY_USECUSTOMCONFIG);
        if (usecustomconfig) {
            String newconfigfile = TCDBprefs.getString(TCDBPreferences.KEY_CONFIGFILE);
            arglist.add("-C" + newconfigfile);
        }

        // Set up the External Command
        ExternalCommandLauncher tcdbtools = new ExternalCommandLauncher(command, arglist, cwd);
        tcdbtools.redirectErrorStream(true);

        MessageConsole console = null;
        // Set the Console (if requested by the user in the preferences)
        if (fPrefsStore.getBoolean(TCDBPreferences.KEY_USECONSOLE) || forceconsole) {
            console = TC32Plugin.getDefault().getConsole("TCDB");
            tcdbtools.setConsole(console);
        }

        ICommandOutputListener outputlistener = new OutputListener(monitor);
        tcdbtools.setCommandOutputListener(outputlistener);

        // Run TCDB
        try {
            fAbortReason = null;
            int result = tcdbtools.launch(new SubProgressMonitor(monitor, 80));

            // Test if TCDB was aborted
            if (fAbortReason != null) {
                throw new TCDBException(fAbortReason, fAbortLine);
            }

            if (result == -1) {
                throw new TCDBException(Reason.USER_CANCEL, "");
            }
        } catch (IOException e) {
            // Something didn't work while running the external command
            throw new TCDBException(Reason.NO_TCDB_FOUND,
                    "Cannot run TCDB executable. Please check the TC32 path preferences.", e);
        }

        // Everything was fine: get the ooutput from TCDB and return it
        // to the caller
        List<String> stdout = tcdbtools.getStdOut();

        monitor.worked(10);

        return stdout;
    } finally {
        monitor.done();
        //fLastTCDBFinish = System.currentTimeMillis();
    }
}

From source file:com.telink.tc32eclipse.core.toolinfo.TCDB.java

License:Open Source License

/**
 * Runs TCDB with the given arguments.// w w w  .j a v  a  2  s  .  co  m
 * <p>
 * The Output of stdout and stderr are merged and returned in a <code>List&lt;String&gt;</code>.
 * If the "use Console" flag is set in the Preferences, the complete output is shown on a
 * Console as well.
 * </p>
 * <p>
 * If the command fails to execute an entry is written to the log and an
 * {@link TCDBException} with the reason is thrown.
 * </p>
 * 
 * @param arguments
 *            <code>List&lt;String&gt;</code> with the arguments
 * @param monitor
 *            <code>IProgressMonitor</code> to cancel the running process.
 * @param forceconsole
 *            If <code>true</code> all output is copied to the console, regardless of the "use
 *            console" flag.
 * @param cwd
 *            <code>IPath</code> with a current working directory or <code>null</code> to use
 *            the default working directory (usually the one defined with the system property
 *            <code>user.dir</code). May not be empty.
 * @param programmerconfig
 *            The TCDB Programmer configuration currently is use. Required for the TCDB
 *            invocation delay value. If <code>null</code> no invocation delay will be done.
 * @return A list of all output lines, or <code>null</code> if the command could not be
 *         launched.
 * @throws TCDBException
 *             when TCDB cannot be started or when TCDB returned an error errors.
 */
public List<String> runCommand(List<String> arglist, IProgressMonitor monitor, boolean forceconsole, IPath cwd,
        ProgrammerConfig programmerconfig) throws TCDBException {

    try {
        monitor.beginTask("Running Telink Tools", 100);

        // Check if the CWD is valid
        if (cwd != null && cwd.isEmpty()) {
            throw new TCDBException(Reason.INVALID_CWD, "CWD does not point to a valid directory.");
        }

        // PS String command = getToolFullPath().toOSString();
        String command = getToolFullPath().toPortableString();

        // Check if the user has a custom configuration file
        IPreferenceStore TCDBprefs = TCDBPreferences.getPreferenceStore();
        boolean usecustomconfig = TCDBprefs.getBoolean(TCDBPreferences.KEY_USECUSTOMCONFIG);

        if (usecustomconfig) {
            String newconfigfile = TCDBprefs.getString(TCDBPreferences.KEY_CONFIGFILE);
            arglist.add("-C" + newconfigfile);
        }

        // Set up the External Command
        ExternalCommandLauncher TCDB = new ExternalCommandLauncher(command, arglist, cwd);
        TCDB.redirectErrorStream(true);

        MessageConsole console = null;
        // Set the Console (if requested by the user in the preferences)
        if (fPrefsStore.getBoolean(TCDBPreferences.KEY_USECONSOLE) || forceconsole) {
            console = TC32Plugin.getDefault().getConsole("Telink Binary Loader Console");
            TCDB.setConsole(console);
        }

        ICommandOutputListener outputlistener = new OutputListener(monitor);
        TCDB.setCommandOutputListener(outputlistener);

        // Run TCDB
        try {
            fAbortReason = null;
            int result = TCDB.launch(new SubProgressMonitor(monitor, 200));

            // Test if TCDB was aborted
            if (fAbortReason != null) {
                throw new TCDBException(fAbortReason, fAbortLine);
            }

            if (result == -1) {
                throw new TCDBException(Reason.USER_CANCEL, "");
            }
        } catch (IOException e) {
            // Something didn't work while running the external command
            throw new TCDBException(Reason.NO_TCDB_FOUND,
                    "Cannot run TCDB executable. Please check the TC32 path preferences.", e);
        }

        // Everything was fine: get the ooutput from TCDB and return it
        // to the caller
        List<String> stdout = TCDB.getStdOut();

        monitor.worked(10);

        return stdout;
    } finally {
        //monitor.done();//JW need reboot mcu
        //fLastTCDBFinish = System.currentTimeMillis();
    }
}

From source file:com.telink.tc32eclipse.ui.dialogs.TCDBErrorDialog.java

License:Open Source License

/**
 * Open an Error Dialog for an TCDBException.
 * <p>//from  w  w  w  . j  a v  a2 s .  c  o  m
 * This method will take the Exception reason from the given {@link TCDBException} and
 * display a human readable message.
 * </p>
 * <p>
 * This Dialog is modal and will block until OK is clicked or the dialog is closed with ESC or
 * the window close button.
 * </P>
 * 
 * @param parent
 *            the parent shell of the dialog, or <code>null</code> if none
 * @param exc
 *            The <code>TCDBException</code> that contains the root cause.
 * @param config
 *            The <code>ProgrammerConfig</code> in use while the Exception occured. Used for
 *            more detailed error messages and may be <code>null</code> if not available.
 */
public static void openTCDBError(Shell parentShell, Throwable exc, ProgrammerConfig config) {
    String message, source;

    if (exc instanceof TCDBException) {
        TCDBException TCDBexc = (TCDBException) exc;

        // Get the Programmer id and the port from the given
        // ProgrammerConfig (if not null)
        // These are used below for more detailed error messages
        String programmer = "";
        String port = "";
        if (config != null) {
            programmer = "\"" + config.getProgrammer() + "\"";
            //port = config.getPort().equals("") ? "" : "\"" + config.getPort() + "\"";
        }

        // Also a custom TCDB configfile might be the cause of errors.
        String customconfig = "";
        IPreferenceStore TCDBstore = TCDBPreferences.getPreferenceStore();
        if (TCDBstore.getBoolean(TCDBPreferences.KEY_USECUSTOMCONFIG)) {
            customconfig = TCDBstore.getString(TCDBPreferences.KEY_CONFIGFILE);
        }

        // The nice thing about enums: using them in a switch statement!
        switch (TCDBexc.getReason()) {
        case UNKNOWN:
            message = "An error occured while accessing TCDB.\n\n" + "See below for details.";
            break;

        case NO_TCDB_FOUND:
            message = "TCDB executable can not be found.\n\n"
                    + "Check in the TC32 Preferences if the path to TCDB is correct.";
            break;

        case CANT_ACCESS_TCDB:
            message = "TCDB executable can not be accessed.\n\n"
                    + "Check in the TC32 Preferences if the path to TCDB is correct\n"
                    + "(Window > Preferences... -> TC32 -> Paths)";
            break;

        case CONFIG_NOT_FOUND:
            if (customconfig.length() == 0) {
                message = "TCDB can not find its default configuration file.\n\n" + "Check your TCDB setup.";
            } else {
                source = "TCDB can not find configuration file [{0}].\n\n"
                        + "Check in the TCDB Preferences if the path to the custom TCDB configuration file is correct\n"
                        + "(Window > Preferences... -> TC32 -> TCDB)";
                message = MessageFormat.format(source, customconfig);
            }
            break;

        case NO_PROGRAMMER:
            message = "No Programmer selected\n\n" + "Check the TCDB properties for the project.";
            break;

        case UNKNOWN_PROGRAMMER:
            source = "TCDB does not recognize the selected programmer id {0}\n\n"
                    + "Check the current Programmer Configuration.";
            message = MessageFormat.format(source, programmer);
            break;

        case UNKNOWN_MCU:
            message = "TCDB does not recognize the selected MCU type.\n\n"
                    + "Check the TC32 Target Hardware settings if the selected MCU is supported by TCDB.";
            break;

        case TIMEOUT:
            source = "Operation timed out while trying to access the TCDB programmer {0}\n\n"
                    + "Check that the Programmer is connected and switched on.";
            message = MessageFormat.format(source, programmer);
            break;

        case PORT_BLOCKED:
            source = "The port {0} for the Programmer {1} is blocked.\n\n"
                    + "Check that no other instances of TCDB or any other programm is using the port";
            message = MessageFormat.format(source, port, programmer);
            break;

        case NO_USB:
            source = "Could not open the USB device with the port name {0}.\n\n" + "Please check that\n"
                    + " - the programmer device is connected an switched on\n\n"
                    + "Also check in the configuration for programmer {1} that\n"
                    + " - the port name is correct\n"
                    + " - the \"Delay between TCDB invocations\" is set to a sufficently high value";
            message = MessageFormat.format(source, port, programmer);
            break;

        case PARSE_ERROR:
            message = "Could not understand the output from TCDB.\n\n"
                    + " - Either TCDB returned an error message that is not covered by the TC32 Eclipse Pluguin\n"
                    + " - or you have a newer TCDB version with a changed output format.\n\n"
                    + "In either case check the TCDB return message below and contact\n";
            break;

        case INVALID_CWD:
            message = "Invalid Build directory.\n"
                    + "Please check the Build directory on the \"Builder settings\" tab\n"
                    + "(Project -> Properties -> C Build)";
            break;

        case USER_CANCEL:
            message = "Operation cancelled.\n";
            break;

        case SYNC_FAIL:
            source = "Programmer {0} could not connect to the target hardware.\n\n"
                    + "Please check that the target hardware is connected correctly.";
            message = MessageFormat.format(source, programmer);
            break;

        case INIT_FAIL:
            source = "Programmer {0} could not initialize the target hardware.\n\n"
                    + "Please check that the target hardware is connected correctly.";
            message = MessageFormat.format(source, programmer);
            break;

        case NO_TARGET_POWER:
            source = "Target Hardware is not powered.\n\n"
                    + "Please check that the target hardware is connected correctly and has power.";
            message = MessageFormat.format(source, programmer);
            break;

        case INVALID_PORT:
            if (port.length() == 0) {
                // The user has not specified a port, so the OS default is used (but seemingly invalid).
                // Try to get the port used by TCDB from the TCDB output
                String abortline = TCDBexc.getMessage();
                String[] split = abortline.split("\"");
                if (split.length >= 2) {
                    port = split[1];
                } else {
                    port = "???";
                }
            }
            source = "TCDB has problems accessing the port \"{0}\".\n\n"
                    + "Please check that the correct port has been selected in the programmer configuration.";
            message = MessageFormat.format(source, port);
            break;

        case USB_RECEIVE_ERROR:
            message = "Problems receiving data from USB\n\n";
            break;

        default:
            message = "An unhandled Error occured while accessing TCDB.\n\n";
        }

    } else {
        // The throwable is not an instance of TCDBException
        // Why does the caller think this class is called
        // TCDBErrorDialog?
        // Nevertheless we just display the message from the Throwable
        message = exc.getLocalizedMessage();
    }

    // Set the status for the dialog
    IStatus status = new Status(IStatus.ERROR, TC32Plugin.PLUGIN_ID, exc.getLocalizedMessage(), exc.getCause());

    // Now open the Dialog.
    // while dialog.open() will return something, we don't care if the user
    // has pressed OK or ESC or the window close button.
    ErrorDialog dialog = new TCDBErrorDialog(parentShell, message, status);
    dialog.open();
    return;
}

From source file:com.threecrickets.creel.eclipse.Builder.java

License:LGPL

/**
 * Creates and configures a Creel engine using plugin preferences and
 * folders.// w  w  w  . j a v  a2s .  c om
 * 
 * @param project
 *        The project
 * @param folders
 *        Map of artifact types to folders
 * @return A Creel engine
 * @throws CoreException
 *         In case of an Eclipse error
 */
public static Engine createEngine(IProject project, Map<Artifact.Type, IContainer> folders)
        throws CoreException {
    IPreferenceStore preferences = Plugin.instance.getPreferenceStore();

    Engine engine = new Engine();
    IOConsole console = EclipseUtil.getConsole("Creel");
    IOConsoleOutputStream stream = console.newOutputStream();
    if (!preferences.getBoolean(PreferencesPage.QUIET))
        ((EventHandlers) engine.getEventHandler()).add(new ConsoleEventHandler(stream, false, false));
    engine.setVerbosity(preferences.getInt(PreferencesPage.VERBOSITY));
    engine.getDirectories().set(toDirectories(folders));

    return engine;
}

From source file:com.vectrace.MercurialEclipse.dialogs.CommitDialog.java

License:Open Source License

/**
 * @param hgRoot// ww  w .  j av a  2s  .  c o  m
 *            non null
 * @param resources
 *            might be null
 */
public CommitDialog(Shell shell, HgRoot hgRoot, List<IResource> resources) {
    super(shell);

    Assert.isNotNull(hgRoot);

    // refresh the project first?
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    boolean refreshFirst = store.getBoolean(MercurialPreferenceConstants.PREF_REFRESH_BEFORE_COMMIT);
    if (refreshFirst) {
        try {
            hgRoot.getResource().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }
    }

    this.root = hgRoot;
    setShellStyle(getShellStyle() | SWT.RESIZE | SWT.TITLE);
    setBlockOnOpen(false);
    inResources = resources;
}

From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    IActionBars actionBars = getHistoryPageSite().getWorkbenchPageSite().getActionBars();
    IMenuManager actionBarsMenu = actionBars.getMenuManager();

    final IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    showTags = store.getBoolean(PREF_SHOW_ALL_TAGS);

    Action toggleShowTags = new Action(Messages.getString("HistoryView.showTags"), //$NON-NLS-1$
            MercurialEclipsePlugin.getImageDescriptor("actions/tag.gif")) { //$NON-NLS-1$
        @Override//w w w  .  ja v a 2s  .  c  om
        public void run() {
            showTags = isChecked();
            store.setValue(PREF_SHOW_ALL_TAGS, showTags);
            if (mercurialHistory != null) {
                refresh();
            }
        }
    };
    toggleShowTags.setChecked(showTags);
    actionBarsMenu.add(toggleShowTags);

    showGraph = store.getBoolean(PREF_SHOW_GRAPH);

    Action toggleShowGraph = new Action(Messages.getString("HistoryView.showGraph"), //$NON-NLS-1$
            MercurialEclipsePlugin.getImageDescriptor("actions/branch.gif")) { //$NON-NLS-1$
        @Override
        public void run() {
            showGraph = isChecked();
            store.setValue(PREF_SHOW_GRAPH, showGraph);
            if (mercurialHistory != null) {
                refresh();
            }
        }
    };
    toggleShowGraph.setChecked(showGraph);
    actionBarsMenu.add(toggleShowGraph);

    showGoTo = store.getBoolean(PREF_SHOW_GOTO_TEXT);
    Action toggleGotoText = new Action("Show 'Go To' Panel", //$NON-NLS-1$
            MercurialEclipsePlugin.getImageDescriptor("actions/goto.gif")) { //$NON-NLS-1$
        @Override
        public void run() {
            showGoTo = isChecked();
            store.setValue(PREF_SHOW_GOTO_TEXT, showGoTo);
            if (mercurialHistory != null) {
                GridData gd = (GridData) gotoPanel.getLayoutData();
                gd.exclude = !showGoTo;
                gotoPanel.setVisible(showGoTo);
                rootControl.layout(false);
                changedPaths.refreshLayout();
            }
        }
    };
    toggleGotoText.setChecked(showGoTo);
    actionBarsMenu.add(toggleGotoText);

    actionShowParentHistory = new Action("Show Parent History", //$NON-NLS-1$
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_UP)) {
        @Override
        public void run() {
            if (mercurialHistory == null || hgRoot != null || resource == null) {
                setEnabled(false);
                return;
            }
            if (resource instanceof IProject) {
                HgRoot root = MercurialTeamProvider.getHgRoot(resource);
                if (root != null) {
                    getHistoryView().showHistoryFor(root, true);
                } else {
                    setEnabled(false);
                }
            } else {
                IContainer parentRes = resource.getParent();
                if (parentRes instanceof IFolder || parentRes instanceof IProject) {
                    getHistoryView().showHistoryFor(parentRes, true);
                } else {
                    setEnabled(false);
                }
            }
        }
    };

    IToolBarManager tbm = actionBars.getToolBarManager();
    tbm.add(new Separator());
    tbm.add(toggleShowTags);
    tbm.add(toggleShowGraph);
    tbm.add(actionShowParentHistory);
    tbm.add(new Separator());
    tbm.add(toggleGotoText);

    rootControl = createComposite(parent);
    createGotoText(rootControl);
    changedPaths = new ChangedPathsPage(this, rootControl);
    createTableHistory(changedPaths.getControl());
    changedPaths.createControl();
    setSelectionProvider(viewer);
    getSite().getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), new Action() {
        @Override
        public void run() {
            copyToClipboard();
        }
    });
}

From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java

License:Open Source License

/**
 * @return an array of length NUMBER_OF_COLUMNS containing the user's preferred
 * column widths or null if they have not been set or if the column width persistence
 * pref (PREF_HISTORY_COLUMN_PERSISTENCE) is not enabled.
 *//*from   w  w w .ja v a2s  . c  o m*/
private static int[] getColumnWidthsFromPrefsIfEnabled() {
    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();

    if (store.getBoolean(PREF_HISTORY_COLUMN_PERSISTENCE) == false) {
        // Column width persistence pref is disabled
        return null;
    }

    String rawWidths = store.getString(PREF_HISTORY_COLUMN_WIDTHS);

    if (rawWidths == null || rawWidths.trim().length() == 0) {
        // No preferred widths have been recorded yet
        return null;
    }

    String[] rawWidthsSplit = rawWidths.split(",");
    int[] parsedWidths = new int[NUMBER_OF_COLUMNS];

    int colIdx = 0;
    while (colIdx < Math.min(rawWidthsSplit.length, NUMBER_OF_COLUMNS)) {
        parsedWidths[colIdx] = Integer.valueOf(rawWidthsSplit[colIdx]);
        colIdx++;
    }

    // This accounts for possible changes in the number of columns.
    if (colIdx < NUMBER_OF_COLUMNS) {
        // The number of columns has been increased. We set default widths and let the
        // user resize as they like.
        for (; colIdx < NUMBER_OF_COLUMNS; colIdx++) {
            parsedWidths[colIdx] = 50;
        }
    } else {
        // Nothing to do: either the number is unchanged or it is lower. We're covered
        // in both cases, meaning that the appropriate number of column data is created.
    }

    return parsedWidths;
}

From source file:com.vectrace.MercurialEclipse.history.MercurialHistoryPage.java

License:Open Source License

private void createTableHistory(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout0 = new GridLayout();
    layout0.marginHeight = 0;/*from  ww  w . j  a  v  a2 s  .c  o m*/
    layout0.marginWidth = 0;
    composite.setLayout(layout0);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.grabExcessVerticalSpace = true;
    composite.setLayoutData(data);

    viewer = new GraphLogTableViewer(composite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.VIRTUAL, this);
    Table changeLogTable = viewer.getTable();

    changeLogTable.setLinesVisible(true);
    changeLogTable.setHeaderVisible(true);

    GridData gridData = new GridData(GridData.FILL_BOTH);
    changeLogTable.setLayoutData(gridData);

    IPreferenceStore store = MercurialEclipsePlugin.getDefault().getPreferenceStore();
    if (layout == null) {
        layout = new TableLayout();

        // Get the user-defined column widths from the preferences.
        int[] preferredWidths = getColumnWidthsFromPrefsIfEnabled();

        // We set default widths when there's no widths in the preferences or the user is not
        // interested in having their custom widths saved.
        if (preferredWidths == null) {
            layout.addColumnData(new ColumnWeightData(7, true));
            layout.addColumnData(new ColumnWeightData(15, true));
            layout.addColumnData(new ColumnWeightData(10, true));
            layout.addColumnData(new ColumnWeightData(10, true));
            layout.addColumnData(new ColumnWeightData(12, true));
            layout.addColumnData(new ColumnWeightData(12, true));
            layout.addColumnData(new ColumnWeightData(25, true));
        } else {
            // We found column widths in the preference store. We use them.
            for (int colIdx = 0; colIdx < NUMBER_OF_COLUMNS; colIdx++) {
                layout.addColumnData(new ColumnPixelData(preferredWidths[colIdx], true));
            }
        }
    }

    changeLogTable.setLayout(layout);
    for (int i = 0; i < NUMBER_OF_COLUMNS; i++) {
        TableColumn column = new TableColumn(changeLogTable, i == 0 ? SWT.CENTER : SWT.LEFT);
        switch (i) {
        case 0:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.graph")); //$NON-NLS-1$
            break;
        case 1:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.changeset")); //$NON-NLS-1$
            break;
        case 2:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.tag")); //$NON-NLS-1$
            break;
        case 3:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.branch")); //$NON-NLS-1$
            break;
        case 4:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.user")); //$NON-NLS-1$
            break;
        case 5:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.date")); //$NON-NLS-1$
            break;
        case 6:
            column.setText(Messages.getString("MercurialHistoryPage.columnHeader.summary")); //$NON-NLS-1$
            break;
        default:
            // If this shows up in the view, then there was a programming error: please update
            // the number of columns constant.
            column.setText("ERROR!!!"); //$NON-NLS-1$
            break;
        }
        //
        // Listener to be notified of changes in the column width.
        if (store.getBoolean(PREF_HISTORY_COLUMN_PERSISTENCE)) {
            column.addControlListener(new ControlListener() {

                public void controlResized(ControlEvent e) {
                    persistColumnWidths();
                }

                public void controlMoved(ControlEvent e) {
                    // We have no interest in this: the columns aren't defined as moveable.
                }
            });
        }
    }
    viewer.setLabelProvider(new ChangeSetLabelProvider());
    viewer.setContentProvider(new ChangeLogContentProvider());
    viewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            getCompareWithPreviousAction();
            updateActionEnablement();
            if (compareWithPrevAction.isEnabled()) {
                compareWithPrevAction.run();
            }
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!gotoText.isVisible()) {
                return;
            }
            IStructuredSelection selection = getSelection();
            if (selection.isEmpty()) {
                return;
            }
            gotoText.setText(((MercurialRevision) selection.getFirstElement()).getChangeSet().toString());
            gotoText.selectAll();
        }
    });

    viewer.getControl().addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            setSelectionProvider(viewer);
        }
    });
    contributeActions();
}