Package org.osgi.service.prefs

Examples of org.osgi.service.prefs.Preferences


            }catch (Exception e) {
                UiPlugin.log("Error creating CRS object, trying more...", e);
            }
        }
        try {
            Preferences child = findNode(code);
            if (child != null) {
                String wkt = child.get(WKT_ID, null);
                if (wkt != null) {
                    try {
                        return ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(wkt);
                    } catch (Exception e) {
                        UiPlugin.log(wkt, e);
                        child.removeNode();
                    }
                }
            }

        } catch (Exception e) {
View Full Code Here


        return null; // should throw an exception?
    }

    private Preferences findNode( String code ) {
        try {
            Preferences root = UiPlugin.getUserPreferences();
            Preferences node = root.node(InstanceScope.SCOPE).node(CUSTOM_ID);

            if (node.nodeExists(code)) {
                return node.node(code);
            }

            for( String id : node.childrenNames() ) {
                Preferences child = node.node(id);
                String name = child.get(NAME_ID, null);
                if (name != null && matchesFilter(name, new String[]{code})) {
                    return child;
                }
            }
            return null;
View Full Code Here

                String text = wktText.getText();
                CoordinateReferenceSystem createdCRS = ReferencingFactoryFinder.getCRSFactory(null)
                        .createFromWKT(text);

                if (keywordsText.getText().trim().length() > 0) {
                    Preferences node = findNode(createdCRS.getName().getCode());
                    if( node!=null ){
                        Preferences kn = node.node(ALIASES_ID);
                        String[] keywords = keywordsText.getText().split(","); //$NON-NLS-1$
                        kn.clear();
                        for( String string : keywords ) {
                            string=string.trim().toUpperCase();
                            if(string.length()>0)
                                kn.put(string,string);
                        }
                        kn.flush();
                    }else{
                        CoordinateReferenceSystem found = createCRS(createdCRS.getName().getCode());
                        if (found != null && CRS.findMathTransform(found, createdCRS, true).isIdentity()) {
                            saveKeywords(found);
                            return found;
View Full Code Here

     * @throws IOException
     * @throws BackingStoreException
     */
    private CoordinateReferenceSystem saveCustomizedCRS( String text, boolean processWKT, CoordinateReferenceSystem createdCRS )
            throws CoreException, IOException, BackingStoreException {
        Preferences root = UiPlugin.getUserPreferences();
        Preferences node = root.node(InstanceScope.SCOPE).node(CUSTOM_ID);
        int lastID;
        String code;
        String name;
        String newWKT;
        if( processWKT ){
            lastID = Integer.parseInt(node.get(LAST_ID, "0")); //$NON-NLS-1$
            code = "UDIG:" + lastID; //$NON-NLS-1$
            name = createdCRS.getName().toString() + "(" + code + ")";//$NON-NLS-1$ //$NON-NLS-2$
            lastID++;
            node.putInt(LAST_ID, lastID);
            newWKT = processingWKT(text, lastID);
        }else{
            Set<ReferenceIdentifier> ids = createdCRS.getIdentifiers();
            if( !ids.isEmpty() ){
                Identifier id = ids.iterator().next();
                code=id.toString();
                name=createdCRS.getName().getCode()+" ("+code+")"; //$NON-NLS-1$ //$NON-NLS-2$
            }else{
                name=code=createdCRS.getName().getCode();
            }
           
            newWKT=text;
        }
       
        Preferences child = node.node(code);
        child.put(NAME_ID, name);
        child.put(WKT_ID, newWKT);
        String[] keywords = keywordsText.getText().split(","); //$NON-NLS-1$
        if (keywords.length > 0) {
            Preferences keyworkNode = child.node(ALIASES_ID);
            for( String string : keywords ) {
                string=string.trim().toUpperCase();
                keyworkNode.put(string, string);
            }
        }
        node.flush();
       
        return createdCRS;
View Full Code Here

     * @throws BackingStoreException
     */
    public void restoreFromPreferences() throws BackingStoreException {
        IPreferencesService prefs = Platform.getPreferencesService();
        IEclipsePreferences root = prefs.getRootNode();
        Preferences node = root.node(InstanceScope.SCOPE).node(
                getBundle().getSymbolicName() + ".bookmarks"); //$NON-NLS-1$

        for( String projectId : node.childrenNames() ) {
            URI projectURI = URI.createURI(URI.decode(projectId));
            Preferences projectNode = node.node(projectId);
            for( String mapId : projectNode.childrenNames() ) {
                URI mapURI = URI.createURI(URI.decode(mapId));
                Preferences mapNode = projectNode.node(mapId);
                String mapName = mapNode.get(KEY_NAME, null);
                for( String bmarkName : mapNode.childrenNames() ) {
                    Preferences bmarkNode = mapNode.node(bmarkName);
                    double minx = bmarkNode.getDouble(KEY_MINX, 0.0);
                    double miny = bmarkNode.getDouble(KEY_MINY, 0.0);
                    double maxx = bmarkNode.getDouble(KEY_MAXX, 0.0);
                    double maxy = bmarkNode.getDouble(KEY_MAXY, 0.0);
                    Envelope env = new Envelope(minx, maxx, miny, maxy);
                    CoordinateReferenceSystem crs;
                    String crsString = bmarkNode.get(KEY_CRS, ""); //$NON-NLS-1$
                    try {
                        crs = CRS.parseWKT(crsString);
                    } catch (NoSuchAuthorityCodeException e) {
                        crs = DefaultGeographicCRS.WGS84;
                    } catch (FactoryException e) {
View Full Code Here

        if (mgr == null) {
            return; // nothing to save!
        }
        IPreferencesService prefs = Platform.getPreferencesService();
        IEclipsePreferences root = prefs.getRootNode();
        Preferences node = root.node(InstanceScope.SCOPE).node(
                getBundle().getSymbolicName() + ".bookmarks"); //$NON-NLS-1$
        clearPreferences(node);
        for( URI project : mgr.getProjects() ) {
            String projectString = project.toString();
            String encPStr = URI.encodeSegment(projectString, true);
            Preferences projectNode = node.node(encPStr);
            for( MapReference map : mgr.getMaps(project) ) {
                Preferences mapNode = projectNode.node(URI.encodeSegment(map.getMapID().toString(),
                        true));
                mapNode.put(KEY_NAME, map.getName());
                for( IBookmark bookmark : mgr.getBookmarks(map) ) {
                    Preferences bmarkNode = mapNode
                            .node(URI.encodeSegment(bookmark.getName(), true));
                    ReferencedEnvelope bounds = bookmark.getEnvelope();
                    bmarkNode.putDouble(KEY_MINX, bounds.getMinX());
                    bmarkNode.putDouble(KEY_MINY, bounds.getMinY());
                    bmarkNode.putDouble(KEY_MAXX, bounds.getMaxX());
                    bmarkNode.putDouble(KEY_MAXY, bounds.getMaxY());
                    bmarkNode.put(KEY_CRS, bounds.getCoordinateReferenceSystem().toWKT());
                }
                mapNode.flush();
            }
            projectNode.flush();
        }
View Full Code Here

        node.flush();
    }

    private void clearPreferences( Preferences node ) throws BackingStoreException {
        for( String name : node.childrenNames() ) {
            Preferences child = node.node(name);
            child.removeNode();
        }
    }
View Full Code Here

  }

  private static void next(int next2) {
        int next=next2;
    try {
      Preferences node = getPreferences();
      List<IConfigurationElement> extensions = ExtensionPointList
          .getExtensionPointList(EXTENSION_ID);
      if (next == -1) {
        Random r = new Random();
        next = r.nextInt(extensions.size());
      }
      for (int i = next; i < extensions.size(); i++) {
        IConfigurationElement elem = extensions.get(i);
        if (isPermittedNext(node, elem)) {
          node.put(elem.getAttribute("id"), ""); //$NON-NLS-1$ //$NON-NLS-2$
          current = new Tip(elem);
          return;
        }
      }
      for (int i = 0; i < next; i++) {
        IConfigurationElement elem = extensions.get(i);
        if (isPermittedNext(node, elem)) {
          node.put(elem.getAttribute("id"), ""); //$NON-NLS-1$ //$NON-NLS-2$
          current = new Tip(elem);
          return;
        }
      }
      if (node.keys().length == 0) {
        current = null;
        return;
      }
      node.clear();
      next(next);
    } catch (Exception e) {
      UiPlugin.log("", e); //$NON-NLS-1$
    }
  }
View Full Code Here

        && isInCurrentConfiguration(elem);
  }

  public static Preferences getPreferences() throws CoreException,
      IOException {
    Preferences userPreferences = UiPlugin.getUserPreferences();
    Preferences node = userPreferences.node(PREFERENCE_ID);
    return node;
  }
View Full Code Here

    @Override
    public void postWindowOpen() {
        super.postWindowOpen();
        try {
            Preferences userPreferences = UiPlugin.getUserPreferences();
            if (!userPreferences.nodeExists("org.locationtech.udig.ui.firstRun")) { //$NON-NLS-1$
                firstRun();
            } else {
                showTip();
            }
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.osgi.service.prefs.Preferences

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.