Package org.eclipse.core.resources

Examples of org.eclipse.core.resources.ProjectScope


   * @return The project-specific value for the given key.
   */
  public String getProjectSpecificPreferencesValue(String key, String def,
      IProject project) {
    assert project != null;
    ProjectScope scope = (ProjectScope) projectToScope.get(project);
    if (scope == null) {
      scope = new ProjectScope(project);
      projectToScope.put(project, scope);
    }
    IEclipsePreferences node = scope.getNode(nodeQualifier);
    if (node != null) {
      return node.get(key, def);
    }
    return null;
  }
View Full Code Here


   * @return boolean When the value was set.
   */
  public boolean setProjectSpecificPreferencesValue(String key, String value,
      IProject project) {
    assert project != null;
    ProjectScope scope = (ProjectScope) projectToScope.get(project);
    if (scope == null) {
      scope = new ProjectScope(project);
      projectToScope.put(project, scope);
    }
    IEclipsePreferences node = scope.getNode(nodeQualifier);
    if (node != null) {
      node.put(key, value);
      try {
        node.flush();
      } catch (BackingStoreException e) {
View Full Code Here

  }

  protected IScopeContext[] createPreferenceScopes(PreferencePage propertyPage) {
    IProject project = getProject(propertyPage);
    if (project != null) {
      return new IScopeContext[] { new ProjectScope(project),
          InstanceScope.INSTANCE, DefaultScope.INSTANCE };
    }
    return new IScopeContext[] { InstanceScope.INSTANCE,
        DefaultScope.INSTANCE };
  }
View Full Code Here

    if (getProject() != null) {
      fEnableProjectSettings = new Button(checkLinkComposite, SWT.CHECK);
      fEnableProjectSettings.setText(SSEUIMessages.EnableProjectSettings);
      fEnableProjectSettings.setLayoutData(new GridData(SWT.BEGINNING,
          SWT.CENTER, false, false));
      boolean enabledForProject = new ProjectScope(getProject()).getNode(
          getPreferenceNodeQualifier()).getBoolean(
          getProjectSettingsKey(), false);
      fEnableProjectSettings.setSelection(enabledForProject);
    } else {
      Label spacer = new Label(checkLinkComposite, SWT.CHECK);
View Full Code Here

  public boolean performOk() {
    boolean ok = super.performOk();
    if (getProject() != null) {
      if (isElementSettingsEnabled()) {
        new ProjectScope(getProject()).getNode(
            getPreferenceNodeQualifier()).putBoolean(
            getProjectSettingsKey(),
            fEnableProjectSettings.getSelection());
      } else {
        new ProjectScope(getProject()).getNode(
            getPreferenceNodeQualifier()).remove(
            getProjectSettingsKey());
      }
      try {
        new ProjectScope(getProject()).getNode(
            getPreferenceNodeQualifier()).flush();
      } catch (BackingStoreException e) {
        Logger.logException(
            "problem saving preference settings to scope " //$NON-NLS-1$
                + new ProjectScope(getProject()).getName(), e);
        ok = false;
      }
    }
    return ok;
  }
View Full Code Here

            return Status.CANCEL_STATUS;
        }
    }

    public void addNature(IProgressMonitor progressMonitor, IProject project) throws CoreException {
        ProjectScope scope = new ProjectScope(project);
        try {
            IEclipsePreferences prefs = scope.getNode(TeaVMEclipsePlugin.ID);
            prefs.flush();
            settingsMap.put(project, new PreferencesBasedTeaVMProjectSettings(project, prefs));
        } catch (BackingStoreException e) {
            throw new RuntimeException("Error creating preferences", e);
        }
View Full Code Here

    private Map<String, ProfileImpl> profileMap = new HashMap<>();
    private IEclipsePreferences globalPreferences;
    private String projectName;

    public PreferencesBasedTeaVMProjectSettings(IProject project) {
        this(project, new ProjectScope(project).getNode(TeaVMEclipsePlugin.ID));
    }
View Full Code Here

  }

  protected IScopeContext[] createPreferenceScopes() {
    IProject project = getProject();
    if (project != null) {
      return new IScopeContext[] { new ProjectScope(project),
          InstanceScope.INSTANCE, DefaultScope.INSTANCE };
    }
    return new IScopeContext[] { InstanceScope.INSTANCE,
        DefaultScope.INSTANCE };
  }
View Full Code Here

                  }
                  Map options = new HashMap(
                      PHPCorePlugin.getOptions());
                  // TODO project may be null
                  IScopeContext[] contents = new IScopeContext[] {
                      new ProjectScope(modelElement
                          .getScriptProject()
                          .getProject()),
                      InstanceScope.INSTANCE,
                      DefaultScope.INSTANCE };
                  for (int i = 0; i < contents.length; i++) {
                    IScopeContext scopeContext = contents[i];
                    IEclipsePreferences node = scopeContext
                        .getNode(PHPCorePlugin.ID);
                    if (node != null) {
                      if (!options
                          .containsKey(PHPCoreConstants.FORMATTER_USE_TABS)) {
                        String useTabs = node
                            .get(PHPCoreConstants.FORMATTER_USE_TABS,
                                null);
                        if (useTabs != null) {
                          options.put(
                              PHPCoreConstants.FORMATTER_USE_TABS,
                              useTabs);
                        }
                      }
                      if (!options
                          .containsKey(PHPCoreConstants.FORMATTER_INDENTATION_SIZE)) {
                        String size = node
                            .get(PHPCoreConstants.FORMATTER_INDENTATION_SIZE,
                                null);
                        if (size != null) {
                          options.put(
                              PHPCoreConstants.FORMATTER_INDENTATION_SIZE,
                              size);
                        }
                      }
                    }
                  }
                  ast.setInsertUseStatement(true);
                  edits = program.rewrite(document, options);
                  edits.apply(document);
                  ast.setInsertUseStatement(false);
                } else if (!useAlias
                    && (usePart == null || !usePartName
                        .equals(usePart
                            .getNamespace()
                            .getFullyQualifiedName()))) {
                  // if the type name already exists, use
                  // fully
                  // qualified name to replace
                  proposal.setReplacementString(NamespaceReference.NAMESPACE_SEPARATOR
                      + fullName);
                }

                // if (useAlias &&
                // needsAliasPrepend(modelElement)) {
                //
                // // update replacement string: add namespace
                // // alias prefix
                // String namespacePrefix = typeName
                // + NamespaceReference.NAMESPACE_SEPARATOR;
                // String replacementString = proposal
                // .getReplacementString();
                //
                // String existingNamespacePrefix =
                // readNamespacePrefix(
                // sourceModule, document, offset,
                // ProjectOptions
                // .getPhpVersion(editorElement));
                //
                // // Add alias to the replacement string:
                // if (!usePartName
                // .equals(existingNamespacePrefix)) {
                // replacementString = namespacePrefix
                // + replacementString;
                // }
                // proposal.setReplacementString(replacementString);
                // }

                if (edits != null) {
                  int replacementOffset = proposal
                      .getReplacementOffset()
                      + edits.getLength();
                  offset += edits.getLength();
                  proposal.setReplacementOffset(replacementOffset);
                }
              }
            }

          }
          return offset;
        }
        return offset;
      }
      // class members should return offset directly
      if (modelElement.getElementType() != IModelElement.TYPE
          && !(modelElement instanceof FakeConstructor)) {
        IModelElement type = modelElement
            .getAncestor(IModelElement.TYPE);
        if (type != null
            && !PHPFlags.isNamespace(((IType) type).getFlags())) {
          return offset;
        }
      }
    } catch (Exception e) {
      Logger.logException(e);
    }

    // add use statement if needed:
    IType namespace = PHPModelUtils.getCurrentNamespace(modelElement);
    if (namespace != null) {

      // find source module of the current editor:
      if (textViewer instanceof PHPStructuredTextViewer) {
        ITextEditor textEditor = ((PHPStructuredTextViewer) textViewer)
            .getTextEditor();
        if (textEditor instanceof PHPStructuredEditor) {
          IModelElement editorElement = ((PHPStructuredEditor) textEditor)
              .getModelElement();
          if (editorElement != null) {
            ISourceModule sourceModule = ((ModelElement) editorElement)
                .getSourceModule();

            try {
              String namespaceName = namespace.getElementName();
              String usePartName = namespaceName;
              boolean useAlias = !Platform
                  .getPreferencesService()
                  .getBoolean(
                      PHPCorePlugin.ID,
                      PHPCoreConstants.CODEASSIST_INSERT_FULL_QUALIFIED_NAME_FOR_NAMESPACE,
                      true, null);
              if (!useAlias) {
                usePartName = usePartName
                    + NamespaceReference.NAMESPACE_SEPARATOR
                    + modelElement.getElementName();
              }
              ModuleDeclaration moduleDeclaration = SourceParserUtil
                  .getModuleDeclaration(sourceModule);
              TextEdit edits = null;

              ASTParser parser = ASTParser
                  .newParser(sourceModule);
              parser.setSource(document.get().toCharArray());
              Program program = parser.createAST(null);

              // don't insert USE statement for current namespace
              if (isSameNamespace(namespaceName, program,
                  sourceModule, offset)) {
                return offset;
              }

              // find existing use statement:
              UsePart usePart = ASTUtils
                  .findUseStatementByNamespace(
                      moduleDeclaration, usePartName,
                      offset);

              List<String> importedTypeName = getImportedTypeName(
                  moduleDeclaration, offset);
              String typeName = ""; //$NON-NLS-1$
              if (!useAlias) {
                typeName = modelElement.getElementName()
                    .toLowerCase();
              } else {
                if (usePart != null
                    && usePart.getAlias() != null
                    && usePart.getAlias().getName() != null) {
                  typeName = usePart.getAlias().getName();
                } else {
                  typeName = PHPModelUtils
                      .extractElementName(namespaceName)
                      .toLowerCase();
                }
              }

              // if the class/namesapce has not been imported
              // add use statement
              if (!importedTypeName.contains(typeName)) {

                program.recordModifications();
                AST ast = program.getAST();
                NamespaceName newNamespaceName = ast
                    .newNamespaceName(
                        createIdentifiers(ast,
                            usePartName), false,
                        false);
                UseStatementPart newUseStatementPart = ast
                    .newUseStatementPart(newNamespaceName,
                        null);
                org.eclipse.php.internal.core.ast.nodes.UseStatement newUseStatement = ast
                    .newUseStatement(Arrays
                        .asList(new UseStatementPart[] { newUseStatementPart }));

                NamespaceDeclaration currentNamespace = getCurrentNamespace(
                    program, sourceModule, offset - 1);
                if (currentNamespace != null) {
                  // insert in the beginning of the
                  // current
                  // namespace:
                  int index = getLastUsestatementIndex(
                      currentNamespace.getBody()
                          .statements(), offset);
                  if (index > 0) {// workaround for bug 393253
                    try {
                      int beginLine = document
                          .getLineOfOffset(currentNamespace
                              .getBody()
                              .statements()
                              .get(index - 1)
                              .getEnd()) + 1;
                      newUseStatement
                          .setSourceRange(
                              document.getLineOffset(beginLine),
                              0);
                    } catch (Exception e) {
                    }
                  }
                  currentNamespace.getBody().statements()
                      .add(index, newUseStatement);
                } else {
                  // insert in the beginning of the
                  // document:
                  int index = getLastUsestatementIndex(
                      program.statements(), offset);
                  if (index > 0) {// workaround for bug 393253
                    try {
                      int beginLine = document
                          .getLineOfOffset(program
                              .statements()
                              .get(index - 1)
                              .getEnd()) + 1;
                      newUseStatement
                          .setSourceRange(
                              document.getLineOffset(beginLine),
                              0);
                    } catch (Exception e) {
                    }
                  }
                  program.statements().add(index,
                      newUseStatement);
                }
                Map options = new HashMap(
                    PHPCorePlugin.getOptions());
                // TODO project may be null
                IScopeContext[] contents = new IScopeContext[] {
                    new ProjectScope(modelElement
                        .getScriptProject()
                        .getProject()),
                    InstanceScope.INSTANCE,
                    DefaultScope.INSTANCE };
                for (int i = 0; i < contents.length; i++) {
View Full Code Here

  // Creates a preferences scope for the given project.
  // This scope will be used to search for preferences values.
  private static IScopeContext[] createPreferenceScopes(IProject project) {
    if (project != null) {
      return new IScopeContext[] { new ProjectScope(project),
          InstanceScope.INSTANCE, DefaultScope.INSTANCE };
    }
    return new IScopeContext[] { InstanceScope.INSTANCE,
        DefaultScope.INSTANCE };
  }
View Full Code Here

TOP

Related Classes of org.eclipse.core.resources.ProjectScope

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.