Example usage for org.eclipse.jface.dialogs IDialogSettings getSections

List of usage examples for org.eclipse.jface.dialogs IDialogSettings getSections

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogSettings getSections.

Prototype

IDialogSettings[] getSections();

Source Link

Document

Returns all the sections in this dialog settings.

Usage

From source file:com.microsoft.tfs.client.common.ui.framework.dialog.DialogSettingsHelper.java

License:Open Source License

public static StoredDialogStatistics[] getStatistics() {
    final IDialogSettings settings = TFSCommonUIClientPlugin.getDefault().getDialogSettings();
    final IDialogSettings[] sections = settings.getSections();
    final List statistics = new ArrayList();
    if (sections != null) {
        for (int i = 0; i < sections.length; i++) {
            statistics.add(createStatistics(sections[i]));
        }/*  w w  w  .j ava  2  s  . co  m*/
    }
    return (StoredDialogStatistics[]) statistics.toArray(new StoredDialogStatistics[] {});
}

From source file:de.blizzy.backup.settings.SettingsManager.java

License:Open Source License

public Settings getSettings() {
    IDialogSettings section = getSection();
    Set<ILocation> locations = new HashSet<>();

    IDialogSettings locationsSection = section.getSection("locations"); //$NON-NLS-1$
    if (locationsSection != null) {
        IDialogSettings[] locationSections = locationsSection.getSections();
        if (locationSections != null) {
            List<LocationProviderDescriptor> descriptors = BackupPlugin.getDefault().getLocationProviders();
            for (IDialogSettings locationSection : locationSections) {
                String type = locationSection.get("__type"); //$NON-NLS-1$
                for (LocationProviderDescriptor desc : descriptors) {
                    if (desc.getLocationProvider().getId().equals(type)) {
                        locations.add(desc.getLocationProvider().getLocation(locationSection));
                        break;
                    }//from www.j  a  v  a2s.c om
                }
            }
        }
    } else {
        // old folders
        String[] savedFolders = section.getArray("folders"); //$NON-NLS-1$
        if (savedFolders != null) {
            for (String folder : savedFolders) {
                locations.add(FileSystemLocationProvider.location(new File(folder)));
            }
        }
    }

    String outputFolder = section.get("outputFolder"); //$NON-NLS-1$
    boolean runHourly = true;
    if (section.get("runHourly") != null) { //$NON-NLS-1$
        runHourly = section.getBoolean("runHourly"); //$NON-NLS-1$
    }
    int dailyHours = 12;
    if (section.get("dailyHours") != null) { //$NON-NLS-1$
        dailyHours = section.getInt("dailyHours"); //$NON-NLS-1$
    }
    int dailyMinutes = 0;
    if (section.get("dailyMinutes") != null) { //$NON-NLS-1$
        dailyMinutes = section.getInt("dailyMinutes"); //$NON-NLS-1$
    }
    boolean useChecksums = false;
    if (section.get("useChecksums") != null) { //$NON-NLS-1$
        useChecksums = section.getBoolean("useChecksums"); //$NON-NLS-1$
    }
    int maxAgeDays = -1;
    if (section.get("maxAgeDays") != null) { //$NON-NLS-1$
        maxAgeDays = section.getInt("maxAgeDays"); //$NON-NLS-1$
    }
    int maxDiskFillRate = 80;
    if (section.get("maxDiskFillRate") != null) { //$NON-NLS-1$
        maxDiskFillRate = section.getInt("maxDiskFillRate"); //$NON-NLS-1$
    }

    return new Settings(locations, outputFolder, runHourly, dailyHours, dailyMinutes, useChecksums, maxAgeDays,
            maxDiskFillRate);
}

From source file:ext.org.eclipse.jdt.internal.ui.javadocexport.RecentSettingsStore.java

License:Open Source License

/**
* Method creates a list of data structes that contain
* The destination, antfile location and the list of library/project references for every
* project in the workspace.Defaults are created for new project.
 * @param settings the settings to load from
*//*w w  w.  j  av a 2s  .  c  o m*/
private void load(IDialogSettings settings) {

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    IDialogSettings projectsSection = settings.getSection(SECTION_PROJECTS);
    if (projectsSection != null) {
        IDialogSettings[] sections = projectsSection.getSections();
        for (int i = 0; i < sections.length; i++) {
            IDialogSettings curr = sections[i];
            String projectName = curr.getName();
            IProject project = root.getProject(projectName);
            //make sure project has not been removed
            if (project.isAccessible()) {
                IJavaProject javaProject = JavaCore.create(project);
                if (!fPerProjectSettings.containsKey(javaProject)) {
                    String hrefs = curr.get(HREF);
                    if (hrefs == null) {
                        hrefs = ""; //$NON-NLS-1$
                    }
                    String destdir = curr.get(DESTINATION);
                    if (destdir == null || destdir.length() == 0) {
                        destdir = getDefaultDestination(javaProject);
                    }
                    String antpath = curr.get(ANTPATH);
                    if (antpath == null || antpath.length() == 0) {
                        antpath = getDefaultAntPath(javaProject);
                    }
                    ProjectData data = new ProjectData();
                    data.setDestination(destdir);
                    data.setAntpath(antpath);
                    data.setHRefs(hrefs);
                    if (!fPerProjectSettings.containsValue(javaProject))
                        fPerProjectSettings.put(javaProject, data);
                }
            }
        }
    }
    //finds projects in the workspace that have been added since the
    //last time the wizard was run
    IProject[] projects = root.getProjects();
    for (int i = 0; i < projects.length; i++) {
        IProject project = projects[i];
        if (project.isAccessible()) {
            IJavaProject curr = JavaCore.create(project);
            if (!fPerProjectSettings.containsKey(curr)) {
                ProjectData data = new ProjectData();
                data.setDestination(getDefaultDestination(curr));
                data.setAntpath(getDefaultAntPath(curr));
                data.setHRefs(""); //$NON-NLS-1$
                fPerProjectSettings.put(curr, data);
            }
        }
    }
}

From source file:net.refractions.udig.catalog.service.database.UserHostPage.java

License:Open Source License

private void populatePreviousConnections(Combo previousConnections) {
    IDialogSettings previous = getDialogSettings().getSection(PREVIOUS_CONNECTIONS);
    if (previous != null) {

        IDialogSettings[] sections = previous.getSections();
        Arrays.sort(sections, new Comparator<IDialogSettings>() {

            public int compare(IDialogSettings o1, IDialogSettings o2) {

                long time1 = o1.getLong(TIMESTAMP);
                long time2 = o2.getLong(TIMESTAMP);
                if (time1 > time2) {
                    return -1;
                }/*from   www . j  a v  a  2  s.c o m*/
                return 1;
            }

        });
        List<String> items = new ArrayList<String>(sections.length);
        items.add(""); //$NON-NLS-1$
        for (IDialogSettings connection : sections) {
            if (!connection.getBoolean(DELETED)) {
                StringBuilder name = new StringBuilder();
                name.append(connection.get(USERNAME));
                name.append('@');
                name.append(connection.get(HOST));
                name.append(':');
                name.append(connection.get(PORT));

                previousConnections.setData(name.toString(), connection);
                items.add(name.toString());
            }
        }

        previousConnections.setItems(items.toArray(new String[0]));
    }
}

From source file:net.refractions.udig.catalog.service.database.UserHostPage.java

License:Open Source License

@Override
public boolean leavingPage() {

    try {/*from  ww w . ja  v a 2  s .  co m*/
        if (!canConnect()) {
            return false;
        } else {
            setErrorMessage(null);
            IDialogSettings section = getDialogSettings().getSection(PREVIOUS_CONNECTIONS);
            if (section == null) {
                section = getDialogSettings().addNewSection(PREVIOUS_CONNECTIONS);
            }

            IDialogSettings[] allSections = section.getSections();
            IDialogSettings match = findMatchForCurrent(allSections);
            if (match != null) {
                if (savePassword.getSelection()) {
                    String storedPass = match.get(PASSWORD);
                    if (!password.getText().equals(storedPass)) {
                        if (storedPass == null || storedPass.length() == 0) {
                            match.put(PASSWORD, password.getText());
                        } else {
                            boolean choice = MessageDialog.openConfirm(getShell(), localization.password,
                                    localization.changePasswordQuery);
                            if (choice) {
                                match.put(PASSWORD, password.getText());
                            }
                        }
                    }

                } else {
                    match.put(PASSWORD, ""); //$NON-NLS-1$
                }

                match.put(SAVE_PASSWORD, savePassword.getSelection());
                match.put(TIMESTAMP, System.currentTimeMillis());
            } else {
                IDialogSettings params = section.addNewSection(allSections.length + 1 + ""); //$NON-NLS-1$
                params.put(HOST, host.getText());
                params.put(PORT, port.getText());
                params.put(USERNAME, username.getText());
                params.put(TIMESTAMP, System.currentTimeMillis());
                params.put(SAVE_PASSWORD, savePassword.getSelection());
                if (savePassword.getSelection()) {
                    params.put(PASSWORD, password.getText());
                }
            }

            return true;
        }
    } catch (InterruptedException e) {
        setMessage(localization.databaseConnectionInterrupted);
        return false;
    }
}

From source file:org.eclipse.m2m.internal.qvt.oml.common.ui.wizards.PersistedValuesWizard.java

License:Open Source License

/**
 * Loads a set of preferences corresponding to the given keys  
 * @param keys - a <code>Map</code> of type String => String (<code>key => value</code>) where the <code>key</code> is name of a key preference
 *               and <code>value</code> if it's value
 * @return a section with preferences which fits the key, if no section fits the key excatly
 *         but some section just doesn't have some of key entries this section is returned (with
 *         lost entries added), if none found a new section is created and with key values set 
 *///  w  ww .j ava2s  .com
public PreferenceSection loadValues(Map<String, ?> keys) {
    // The root section, corresponding to the wizard
    IDialogSettings section = myPlugin.getDialogSettings().getSection(getClass().getName());
    if (section == null) {
        section = myPlugin.getDialogSettings().addNewSection(getClass().getName());
    }
    // Different wizard configurations
    String name = "0"; //$NON-NLS-1$
    IDialogSettings[] sections = section.getSections();
    PreferenceSection result;
    if ((sections == null) || (sections.length == 0)) {
        result = new PreferenceSection(section, name);
    } else {
        IDialogSettings resSection = null;
        // Looking for a section satisfying the key with the latest timestamp 
        for (int i = 0; i < sections.length; i++) {
            int equal = checkSectionEquals(sections[i], keys);
            switch (equal) {
            case SECTIONS_EQUAL:
                if ((resSection == null) || (resSection.getLong(TIMESTAMP) < sections[i].getLong(TIMESTAMP))) {
                    resSection = sections[i];
                }
                break;
            case SECTIONS_EQUAL_WITH_IMPLIED:
                if (resSection == null) {
                    resSection = sections[i];
                }
                break;
            }
        }
        if (resSection == null) {
            result = getFreeSubsection(section);
        } else {
            result = new PreferenceSection(resSection, PreferenceSection.DONT_ERASE_DATA);
        }
    }
    initSection(result, keys);
    return result;
}

From source file:org.eclipse.m2m.internal.qvt.oml.common.ui.wizards.PersistedValuesWizard.java

License:Open Source License

/**
 * Finds a free subsection of the given section. If the maximum number of sections 
 * isn't reached, cretes a new subsection, otherwise returns the most old subsection
 * considering it to be replaced //from   w  w w.  jav a2 s  .co  m
 * @param section - a root section
 * @return a reference to a free section object
 */
private PreferenceSection getFreeSubsection(IDialogSettings section) {
    IDialogSettings[] subsections = section.getSections();
    if (subsections == null) {
        return new PreferenceSection(section, "0"); //$NON-NLS-1$
    }
    if (subsections.length < MAX_RECORDS) {
        return new PreferenceSection(section, String.valueOf(subsections.length));
    }
    IDialogSettings toReplace = subsections[0];
    for (int i = 1; i < subsections.length; i++) {
        if (toReplace.getLong(TIMESTAMP) > subsections[i].getLong(TIMESTAMP)) {
            toReplace = subsections[i];
        }
    }
    return new PreferenceSection(toReplace, PreferenceSection.ERASE_DATA);
}

From source file:org.eclipse.rcptt.ctx.preferences.impl.DialogSettingsUtils.java

License:Open Source License

private static PrefNode convertDialogSettings(IDialogSettings settings) {
    List<PrefNode> childNodes = null;
    List<PrefData> data = null;

    IDialogSettings[] childs = settings.getSections();
    for (IDialogSettings child : childs) {
        PrefNode childNode = convertDialogSettings(child);
        if (childNode != null) {
            if (childNodes == null) {
                childNodes = new ArrayList<PrefNode>();
            }//from  w ww  . j a  va 2s  . co m
            childNodes.add(childNode);
        }
    }

    Object[] itemKeys = getItemKeys(settings);
    Object[] arrayItemKeys = getArrayItemKeys(settings);
    if (itemKeys.length > 0 || arrayItemKeys.length > 0) {
        data = new ArrayList<PrefData>();

        for (Object key : itemKeys) {
            String itemKey = (String) key;
            StringPrefData stringData = PreferencesFactory.eINSTANCE.createStringPrefData();
            stringData.setKey(itemKey);
            String value = settings.get(itemKey);
            value = PrefUtils.encodeWorkspaceLocation(value);
            stringData.setValue(value);
            data.add(stringData);
        }

        for (Object key : arrayItemKeys) {
            String arrayItemKey = (String) key;
            ListPrefData listPrefData = PreferencesFactory.eINSTANCE.createListPrefData();
            listPrefData.setKey(arrayItemKey);
            String[] values = settings.getArray(arrayItemKey);
            for (String value : values) {
                value = PrefUtils.encodeWorkspaceLocation(value);
                listPrefData.getValues().add(value);
            }
            data.add(listPrefData);
        }
    }

    if (childNodes != null || data != null) {
        PrefNode prefNode = PreferencesFactory.eINSTANCE.createPrefNode();
        prefNode.setName(settings.getName());
        if (childNodes != null) {
            prefNode.getChilds().addAll(childNodes);
        }
        if (data != null) {
            prefNode.getData().addAll(data);
        }
        return prefNode;
    }
    return null;
}

From source file:org.eclipse.wst.jsdt.internal.ui.javadocexport.RecentSettingsStore.java

License:Open Source License

/**
* Method creates a list of data structes that contain
* The destination, antfile location and the list of library/project references for every
* project in the workspace.Defaults are created for new project.
*//*from   w w w .j a  va  2s.c  om*/
private void load(IDialogSettings settings) {

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    IDialogSettings projectsSection = settings.getSection(SECTION_PROJECTS);
    if (projectsSection != null) {
        IDialogSettings[] sections = projectsSection.getSections();
        for (int i = 0; i < sections.length; i++) {
            IDialogSettings curr = sections[i];
            String projectName = curr.getName();
            IProject project = root.getProject(projectName);
            //make sure project has not been removed
            if (project.isAccessible()) {
                IJavaScriptProject javaProject = JavaScriptCore.create(project);
                if (!fPerProjectSettings.containsKey(javaProject)) {
                    String hrefs = curr.get(HREF);
                    if (hrefs == null) {
                        hrefs = ""; //$NON-NLS-1$
                    }
                    String destdir = curr.get(DESTINATION);
                    if (destdir == null || destdir.length() == 0) {
                        destdir = getDefaultDestination(javaProject);
                    }
                    String antpath = curr.get(ANTPATH);
                    if (antpath == null || antpath.length() == 0) {
                        antpath = getDefaultAntPath(javaProject);
                    }
                    ProjectData data = new ProjectData();
                    data.setDestination(destdir);
                    data.setAntpath(antpath);
                    data.setHRefs(hrefs);
                    if (!fPerProjectSettings.containsValue(javaProject))
                        fPerProjectSettings.put(javaProject, data);
                }
            }
        }
    }
    //finds projects in the workspace that have been added since the
    //last time the wizard was run
    IProject[] projects = root.getProjects();
    for (int i = 0; i < projects.length; i++) {
        IProject project = projects[i];
        if (project.isAccessible()) {
            IJavaScriptProject curr = JavaScriptCore.create(project);
            if (!fPerProjectSettings.containsKey(curr)) {
                ProjectData data = new ProjectData();
                data.setDestination(getDefaultDestination(curr));
                data.setAntpath(getDefaultAntPath(curr));
                data.setHRefs(""); //$NON-NLS-1$
                fPerProjectSettings.put(curr, data);
            }
        }
    }
}

From source file:org.eclipsetrader.news.internal.Activator.java

License:Open Source License

public IDialogSettings getDialogSettingsForView(URI uri) {
    String uriString = uri.toString();

    IDialogSettings rootSettings = getDialogSettings().getSection("Views");
    if (rootSettings == null) {
        rootSettings = getDialogSettings().addNewSection("Views");
    }//w w  w . j  ava  2s  .  co  m

    IDialogSettings[] sections = rootSettings.getSections();
    for (int i = 0; i < sections.length; i++) {
        if (uriString.equals(sections[i].get("uri"))) {
            return sections[i];
        }
    }

    String uuid = UUID.randomUUID().toString();
    IDialogSettings dialogSettings = rootSettings.addNewSection(uuid);
    dialogSettings.put("uri", uriString);

    return dialogSettings;
}