Search in sources :

Example 11 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project org.csstudio.display.builder by kasemir.

the class Preferences method getTimespanShortcuts.

/**
 * @return Array where [N][0] is display text and [N][1] is the 'start' time
 */
public static String[][] getTimespanShortcuts() {
    String shortcuts = "1 Day,-1 days|7 Days,-7 days";
    final IPreferencesService prefs = Platform.getPreferencesService();
    if (prefs != null)
        shortcuts = prefs.getString(Activator.PLUGIN_ID, TIME_SPAN_SHORTCUTS, shortcuts, null);
    final List<List<String>> items = new ArrayList<>();
    for (String item : shortcuts.split("\\|")) {
        final String[] display_start = item.split(", *");
        if (display_start.length != 2) {
            Activator.getLogger().log(Level.WARNING, "Invalid " + TIME_SPAN_SHORTCUTS + " value " + item);
            continue;
        }
        items.add(Arrays.asList(display_start));
    }
    final String[][] result = new String[items.size()][2];
    for (int i = 0; i < items.size(); ++i) {
        result[i][0] = items.get(i).get(0);
        result[i][1] = items.get(i).get(1);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 12 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project org.csstudio.display.builder by kasemir.

the class Preferences method getArchiveServerURLs.

public static ArchiveServerURL[] getArchiveServerURLs() {
    final IPreferencesService prefs = Platform.getPreferencesService();
    final String urls = prefs.getString(Activator.PLUGIN_ID, URLS, "", null).trim();
    if (urls.length() <= 0)
        return new ArchiveServerURL[0];
    ArrayList<ArchiveServerURL> list = new ArrayList<ArchiveServerURL>();
    for (String fragment : urls.split("\\*")) {
        String[] strs = fragment.split("\\|");
        if (strs.length == 1)
            list.add(new ArchiveServerURL(strs[0], null));
        else if (strs.length >= 2)
            list.add(new ArchiveServerURL(strs[0], strs[1]));
    }
    return list.toArray(new ArchiveServerURL[list.size()]);
}
Also used : ArrayList(java.util.ArrayList) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService)

Example 13 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project eclipse-integration-commons by spring-projects.

the class CorePlugin method getUUID.

public static synchronized String getUUID() {
    ServiceReference ref = getDefault().getBundle().getBundleContext().getServiceReference(IPreferencesService.class.getName());
    IPreferencesService prefService = (IPreferencesService) getDefault().getBundle().getBundleContext().getService(ref);
    try {
        IEclipsePreferences prefs = (IEclipsePreferences) prefService.getRootNode().node(InstanceScope.SCOPE);
        Preferences p = prefs.node(PLUGIN_ID);
        if (StringUtils.isEmpty(p.get(UUID_PROPERTY_KEY, ""))) {
            p.put(UUID_PROPERTY_KEY, UUID.randomUUID().toString());
        }
        return p.get(UUID_PROPERTY_KEY, "");
    } finally {
        if (prefService != null) {
            getDefault().getBundle().getBundleContext().ungetService(ref);
        }
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.osgi.service.prefs.Preferences) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) ServiceReference(org.osgi.framework.ServiceReference)

Example 14 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project mdw-designer by CenturyLinkCloud.

the class WorkspaceConfigurator method loadPreferences.

/**
 * Loads preferences from the workspace setup site.
 *
 * @return <code>true</code> if the load was successful
 */
protected boolean loadPreferences() {
    // import all
    IPreferenceFilter[] filters = new IPreferenceFilter[1];
    filters[0] = new IPreferenceFilter() {

        public String[] getScopes() {
            return new String[] { InstanceScope.SCOPE, ConfigurationScope.SCOPE };
        }

        public Map<String, PreferenceFilterEntry[]> getMapping(String scope) {
            return null;
        }
    };
    String baseUrl = getWorkspaceConfig().getMdwSettings().getWorkspaceSetupUrl();
    if (!baseUrl.endsWith("/"))
        baseUrl += "/";
    InputStream is = null;
    try {
        URL url = new URL(baseUrl + "MdwWorkspaceSetup.epf");
        URLConnection connection = url.openConnection();
        is = connection.getInputStream();
        IPreferencesService service = Platform.getPreferencesService();
        IExportedPreferences prefs = service.readPreferences(is);
        service.applyPreferences(prefs, filters);
    } catch (Exception ex) {
        PluginMessages.uiError(getShell(), ex, "Workspace Setup");
        return false;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            // do nothing
            }
        }
    }
    return true;
}
Also used : PreferenceFilterEntry(org.eclipse.core.runtime.preferences.PreferenceFilterEntry) InputStream(java.io.InputStream) IExportedPreferences(org.eclipse.core.runtime.preferences.IExportedPreferences) IPreferenceFilter(org.eclipse.core.runtime.preferences.IPreferenceFilter) IOException(java.io.IOException) Map(java.util.Map) URL(java.net.URL) URLConnection(java.net.URLConnection) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException)

Example 15 with IPreferencesService

use of org.eclipse.core.runtime.preferences.IPreferencesService in project titan.EclipsePlug-ins by eclipse.

the class Activator method batchedEventHandler.

/**
 * Handle the resource changes that has been batched.
 */
protected void batchedEventHandler() {
    projects = new HashMap<IProject, IResourceDelta>();
    for (final IResourceChangeEvent event : BATCHED_EVENTS) {
        final IResourceDelta resourceDelta = event.getDelta();
        if (resourceDelta == null) {
            switch(event.getType()) {
                case IResourceChangeEvent.PRE_CLOSE:
                case IResourceChangeEvent.PRE_DELETE:
                    GlobalParser.clearAllInformation(event.getResource().getProject());
                    break;
                default:
                    break;
            }
        } else {
            try {
                resourceDelta.accept(projectAdder);
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
            MarkerHandler.handleResourceChanges(event);
        }
    }
    BATCHED_EVENTS.clear();
    final IPreferencesService prefs = Platform.getPreferencesService();
    // for every project check if the TITANProperties file was changed or need to be changed
    for (final IProject project : projects.keySet()) {
        // which can be handled
        if (project != null && project.isAccessible() && projects.get(project) != null) {
            final IResourceDelta projectDelta = projects.get(project);
            if (projectDelta.getKind() == IResourceDelta.ADDED) {
                // new project appeared load the settings
                final ProjectFileHandler pfHandler = new ProjectFileHandler(project);
                pfHandler.loadProjectSettings();
                PropertyNotificationManager.firePropertyChange(project);
                continue;
            }
            try {
                final IResourceDelta propertiesDelta = projectDelta.findMember(new Path(ProjectFileHandler.XML_TITAN_PROPERTIES_FILE));
                final DeltaVisitor visitor = new DeltaVisitor();
                projectDelta.accept(visitor);
                if (visitor.hasNewOrRemovedResources()) {
                    final ProjectFileHandler pfHandler = new ProjectFileHandler(project);
                    if (propertiesDelta == null || propertiesDelta.getKind() == IResourceDelta.REMOVED) {
                        // project setting file does not exist
                        pfHandler.saveProjectSettings();
                    } else {
                        // the project settings have changed and we have new resources, the project was updated by the user
                        pfHandler.loadProjectSettings();
                        PropertyNotificationManager.firePropertyChange(project);
                    }
                } else {
                    if (propertiesDelta != null) {
                        final ProjectFileHandler pfHandler = new ProjectFileHandler(project);
                        if (propertiesDelta.getKind() == IResourceDelta.REMOVED) {
                            // save the settings if the only change was that it was removed externally
                            pfHandler.saveProjectSettings();
                        } else {
                            // load the settings if it changed
                            pfHandler.loadProjectSettings();
                            PropertyNotificationManager.firePropertyChange(project);
                        }
                    }
                }
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace(e);
            }
            // check if it needs to be built, if full analysis is needed, and that the working directory is always set as derived
            final IProject[] referencingProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getReferencingProjects();
            for (int i = 0; i < referencingProjects.length; i++) {
                ProjectBasedBuilder.setForcedBuild(referencingProjects[i]);
            }
            if ((projectDelta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
                TITANBuilder.markProjectForRebuild(project);
            }
            if (projectDelta.getKind() == IResourceDelta.ADDED) {
                final WorkspaceJob derivedSetter = new WorkspaceJob("Derived flag setter") {

                    @Override
                    public IStatus runInWorkspace(final IProgressMonitor monitor) {
                        final IContainer[] workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(true);
                        for (IContainer workingDirectory : workingDirectories) {
                            if (workingDirectory != null && workingDirectory.isAccessible()) {
                                try {
                                    workingDirectory.setDerived(true, monitor);
                                } catch (CoreException e) {
                                    ErrorReporter.logExceptionStackTrace(e);
                                }
                            }
                        }
                        return Status.OK_STATUS;
                    }
                };
                derivedSetter.setPriority(Job.LONG);
                derivedSetter.setUser(false);
                derivedSetter.setSystem(true);
                derivedSetter.setRule(project.getWorkspace().getRuleFactory().modifyRule(project));
                derivedSetter.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
                derivedSetter.schedule();
            }
        }
    }
    // we need to invoke the analyzer to refresh the information databases.
    if (prefs.getBoolean(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.USEONTHEFLYPARSING, true, null)) {
        for (final IProject project : projects.keySet()) {
            // which can be handled
            if (project != null && project.isAccessible() && projects.get(project) != null) {
                final IResourceDelta projectDelta = projects.get(project);
                final DeltaVisitor visitor = new DeltaVisitor();
                try {
                    projectDelta.accept(visitor);
                    if (!visitor.hasNewOrRemovedResources() && (projectDelta.getFlags() & IResourceDelta.DESCRIPTION) == 0) {
                        continue;
                    }
                } catch (CoreException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                }
                final WorkspaceJob buildStarter = new WorkspaceJob("Build starter") {

                    @Override
                    public IStatus runInWorkspace(final IProgressMonitor monitor) {
                        GlobalDeltaVisitor tempVisitor = new GlobalDeltaVisitor(project);
                        try {
                            projectDelta.accept(tempVisitor);
                        } catch (CoreException e) {
                            ErrorReporter.logExceptionStackTrace(e);
                        }
                        final WorkspaceJob[] outdatingJobs = tempVisitor.reportOutdatedFiles();
                        WorkspaceJob analyzeAfterOutdating = new WorkspaceJob("analyzeAfterOutdating") {

                            @Override
                            public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                                // Wait for reportOutdatedFiles() to finish
                                try {
                                    for (WorkspaceJob job : outdatingJobs) {
                                        if (job != null) {
                                            job.join();
                                        }
                                    }
                                } catch (InterruptedException e) {
                                    ErrorReporter.logExceptionStackTrace(e);
                                }
                                GlobalParser.getProjectSourceParser(project).analyzeAll(false);
                                if (ProjectBuildPropertyData.useAutomaticMakefilegeneration(project)) {
                                    TITANBuilder.markProjectForRebuild(project);
                                    TITANBuilder.regenerateMakefile(project);
                                }
                                return Status.OK_STATUS;
                            }
                        };
                        analyzeAfterOutdating.setPriority(Job.LONG);
                        analyzeAfterOutdating.setUser(false);
                        analyzeAfterOutdating.setSystem(true);
                        analyzeAfterOutdating.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
                        analyzeAfterOutdating.schedule();
                        return Status.OK_STATUS;
                    }
                };
                buildStarter.setPriority(Job.LONG);
                buildStarter.setUser(false);
                buildStarter.setSystem(true);
                buildStarter.setRule(project.getWorkspace().getRuleFactory().refreshRule(project));
                buildStarter.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
                buildStarter.schedule();
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) CoreException(org.eclipse.core.runtime.CoreException) ProjectFileHandler(org.eclipse.titan.designer.properties.data.ProjectFileHandler) IContainer(org.eclipse.core.resources.IContainer) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)96 IFile (org.eclipse.core.resources.IFile)26 ArrayList (java.util.ArrayList)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)13 Module (org.eclipse.titan.designer.AST.Module)11 ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)11 List (java.util.List)10 File (java.io.File)8 TextSelection (org.eclipse.jface.text.TextSelection)8 Path (org.eclipse.core.runtime.Path)6 IContainer (org.eclipse.core.resources.IContainer)5 IMarker (org.eclipse.core.resources.IMarker)5 IPath (org.eclipse.core.runtime.IPath)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)5 IOException (java.io.IOException)4 IStatus (org.eclipse.core.runtime.IStatus)4