Exemplo n.º 1
0
  private boolean login(final MonitorServer server) {
    boolean firstTry = true;
    SecureLoginDialog loginDialog = new SecureLoginDialog(null);
    while (!(MonitorServerManager.getInstance().getLoginSucess())) {
      IPreferencesService service = Platform.getPreferencesService();
      boolean auto_login =
          service.getBoolean(Application.PLUGIN_ID, GeneralPreferencePage.AUTO_LOGIN, false, null);
      MonitorServer details = loginDialog.getConnectionDetails();
      if (!auto_login || details == null || !firstTry) {
        if (loginDialog.open() != Window.OK) return false;
        details = loginDialog.getConnectionDetails();
      }
      firstTry = false;

      //			session.setConnectionDetails(details);
      //			MonitorServerManager.getInstance().registerServer(server);
      MonitorServerManager.getInstance().setCurServer(details);
      try {
        MonitorServerManager.getInstance().registerServer(details);
      } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (NotBoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      connectWithProgress(details);
    }
    return true;
  }
Exemplo n.º 2
0
 public static boolean getUseCache() {
   final IPreferencesService service = Platform.getPreferencesService();
   if (service == null) {
     return false;
   }
   return service.getBoolean(Activator.PLUGIN_ID, USE_CACHE, false, null);
 }
Exemplo n.º 3
0
 public static int getCacheMaxSize() {
   final IPreferencesService service = Platform.getPreferencesService();
   if (service == null) {
     return 100;
   }
   return service.getInt(Activator.PLUGIN_ID, CACHE_MAX_SIZE, 100, null);
 }
Exemplo n.º 4
0
  /**
   * look up a preference value.
   *
   * <p>will return user settings if available or default settings if not. If a system property with
   * the given key is defined it will overrule any existing setting in the preference store. if the
   * key is not defined, this method returns the given default..
   *
   * @param key
   * @return the value or specified default if no such key exists..
   */
  public String getPreferenceValue(String key, String defaultValue) {

    IPreferencesService service = Platform.getPreferencesService();
    String qualifier = getBundle().getSymbolicName();
    String value = service.getString(qualifier, key, defaultValue, null);
    return System.getProperty(key, value);
  }
 public Map<String, ? extends Object> getInitServerProperties() {
   final Map<String, Object> map = new HashMap<String, Object>();
   final IPreferencesService preferences = Platform.getPreferencesService();
   final AtomicReference<double[]> dpi = new AtomicReference<double[]>();
   dpi.set(
       RGraphicsPreferencePage.parseDPI(
           preferences.getString(
               RGraphics.PREF_DISPLAY_QUALIFIER,
               RGraphics.PREF_DISPLAY_CUSTOM_DPI_KEY,
               null,
               null)));
   if (dpi.get() == null) {
     Display.getDefault()
         .syncExec(
             new Runnable() {
               public void run() {
                 final Point point = Display.getCurrent().getDPI();
                 dpi.set(new double[] {point.x, point.y});
               }
             });
     if (dpi.get() == null) {
       dpi.set(new double[] {96.0, 96.0});
     }
   }
   map.put("display.ppi", dpi.get()); // $NON-NLS-1$
   return map;
 }
Exemplo n.º 6
0
 /**
  * @param key the name of the preference (optionally including its path)
  * @param defaultValue the value to use if the preference is not defined
  * @param project optional project object to honor project scoped preferences
  * @return the value of the preference or the given default value
  */
 private String getStringPreferencesValue(String key, String defaultValue, IProject project) {
   IPreferencesService service = Platform.getPreferencesService();
   String qualifier = getSymbolicName();
   if (project != null) {
     IScopeContext[] contexts = new IScopeContext[] {new ProjectScope(project)};
     return service.getString(qualifier, key, defaultValue, contexts);
   } else {
     return service.getString(qualifier, key, defaultValue, null);
   }
 }
 public void testBadContext() {
   IScopeContext context = new BadTestScope();
   IPreferencesService service = Platform.getPreferencesService();
   try {
     context.getNode("qualifier");
     fail("0.5"); // should throw an exception
   } catch (RuntimeException e) {
     // expected
   }
   assertNull("1.0", service.getString("qualifier", "foo", null, new IScopeContext[] {context}));
 }
  /* (non-Javadoc)
   * @see org.eclipse.ui.internal.wizards.preferences.WizardPreferencesPage#getTransfers()
   */
  protected PreferenceTransferElement[] getTransfers() {
    if (validFromFile()) {
      FileInputStream fis;

      try {
        fis = new FileInputStream(getDestinationValue());
      } catch (FileNotFoundException e) {
        WorkbenchPlugin.log(e.getMessage(), e);
        return new PreferenceTransferElement[0];
      }
      IPreferencesService service = Platform.getPreferencesService();
      try {
        IExportedPreferences prefs;
        prefs = service.readPreferences(fis);
        PreferenceTransferElement[] transfers = super.getTransfers();
        IPreferenceFilter[] filters = new IPreferenceFilter[transfers.length];
        for (int i = 0; i < transfers.length; i++) {
          PreferenceTransferElement transfer = transfers[i];
          filters[i] = transfer.getFilter();
        }
        IPreferenceFilter[] matches = service.matches(prefs, filters);
        PreferenceTransferElement[] returnTransfers = new PreferenceTransferElement[matches.length];
        int index = 0;
        for (int i = 0; i < matches.length; i++) {
          IPreferenceFilter filter = matches[i];
          for (int j = 0; j < transfers.length; j++) {
            PreferenceTransferElement element = transfers[j];
            if (element.getFilter().equals(filter)) {
              returnTransfers[index++] = element;
            }
          }
        }

        PreferenceTransferElement[] destTransfers = new PreferenceTransferElement[index];
        System.arraycopy(returnTransfers, 0, destTransfers, 0, index);
        return destTransfers;
      } catch (CoreException e) {
        // Do not log core exceptions, they indicate the chosen file is not valid
        // WorkbenchPlugin.log(e.getMessage(), e);
      } finally {
        try {
          fis.close();
        } catch (IOException e) {
          WorkbenchPlugin.log(e.getMessage(), e);
        }
      }
    }

    return new PreferenceTransferElement[0];
  }
  /**
   * @param filters
   * @return <code>true</code> if the transfer was succesful, and <code>false</code> otherwise
   */
  protected boolean transfer(IPreferenceFilter[] filters) {
    File importFile = new File(getDestinationValue());
    FileInputStream fis = null;
    try {
      if (filters.length > 0) {
        try {
          fis = new FileInputStream(importFile);
        } catch (FileNotFoundException e) {
          WorkbenchPlugin.log(e.getMessage(), e);
          MessageDialog.open(
              MessageDialog.ERROR,
              getControl().getShell(),
              new String(),
              e.getLocalizedMessage(),
              SWT.SHEET);
          return false;
        }
        IPreferencesService service = Platform.getPreferencesService();
        try {
          IExportedPreferences prefs = service.readPreferences(fis);

          service.applyPreferences(prefs, filters);
        } catch (CoreException e) {
          WorkbenchPlugin.log(e.getMessage(), e);
          MessageDialog.open(
              MessageDialog.ERROR,
              getControl().getShell(),
              new String(),
              e.getLocalizedMessage(),
              SWT.SHEET);
          return false;
        }
      }
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
          WorkbenchPlugin.log(e.getMessage(), e);
          MessageDialog.open(
              MessageDialog.ERROR,
              getControl().getShell(),
              new String(),
              e.getLocalizedMessage(),
              SWT.SHEET);
        }
      }
    }
    return true;
  }
Exemplo n.º 10
0
  private void loadSaved() {
    // Preferences preferences = Activator.getDefault().getPluginPreferences();
    final IPreferencesService service = Platform.getPreferencesService();

    if (toolGroups != null) {
      for (final BinDirPanel toolGroup : toolGroups) {
        toolGroup.binDir.setText(
            service.getString(
                Activator.PLUGIN_ID,
                IToolLaunchConfigurationConstants.TOOL_BIN_ID + "." + toolGroup.group,
                "",
                null)); // ITAULaunchConfigurationConstants.TAU_BIN_PATH)); //$NON-NLS-1$
      }
    }
  }
  /**
   * Creates a combo box and associates the combo data with the combo box.
   *
   * @param composite the composite to create the combo box in
   * @param key the unique key to identify the combo box
   * @param values the values represented by the combo options
   * @param valueLabels the values displayed in the combo box
   * @return the generated combo box
   */
  protected Combo newComboControl(
      Composite composite, String key, int[] values, String[] valueLabels) {
    ComboData data = new ComboData(key, values, -1);

    Combo comboBox = new Combo(composite, SWT.READ_ONLY);
    comboBox.setItems(valueLabels);
    comboBox.setData(data);
    comboBox.addSelectionListener(getSelectionListener());
    comboBox.setFont(JFaceResources.getDialogFont());

    makeScrollableCompositeAware(comboBox);

    int severity = -1;
    if (key != null)
      severity =
          fPreferencesService.getInt(
              getPreferenceNodeQualifier(),
              key,
              ValidationMessage.WARNING,
              createPreferenceScopes());

    if (severity == ValidationMessage.ERROR
        || severity == ValidationMessage.WARNING
        || severity == ValidationMessage.IGNORE) {
      data.setSeverity(severity);
      data.originalSeverity = severity;
    }

    if (data.getIndex() >= 0) comboBox.select(data.getIndex());

    fCombos.add(comboBox);
    return comboBox;
  }
Exemplo n.º 12
0
 private static boolean getBoolean(IJavaProject jproj, String optionName) {
   IPreferencesService service = Platform.getPreferencesService();
   IScopeContext[] contexts;
   if (jproj != null) {
     contexts =
         new IScopeContext[] {
           new ProjectScope(jproj.getProject()), InstanceScope.INSTANCE, DefaultScope.INSTANCE
         };
   } else {
     contexts = new IScopeContext[] {InstanceScope.INSTANCE, DefaultScope.INSTANCE};
   }
   return service.getBoolean(
       AptPlugin.PLUGIN_ID,
       optionName,
       Boolean.parseBoolean(AptPreferenceConstants.DEFAULT_OPTIONS_MAP.get(optionName)),
       contexts);
 }
Exemplo n.º 13
0
 public HeaderSubstitutor(InclusionContext context) {
   fContext = context;
   fIncludeMaps = new IncludeMap[] {new IncludeMap(true), new IncludeMap(false)};
   IPreferencesService preferences = Platform.getPreferencesService();
   IScopeContext[] scopes = PreferenceConstants.getPreferenceScopes(context.getProject());
   String str =
       preferences.getString(
           CUIPlugin.PLUGIN_ID, PreferenceConstants.INCLUDES_HEADER_SUBSTITUTION, null, scopes);
   if (str != null) {
     List<HeaderSubstitutionMap> maps = HeaderSubstitutionMap.deserializeMaps(str);
     for (HeaderSubstitutionMap map : maps) {
       if (!map.isCppOnly() || fContext.isCXXLanguage()) {
         fIncludeMaps[0].addAllMappings(map.getUnconditionalSubstitutionMap());
         fIncludeMaps[1].addAllMappings(map.getOptionalSubstitutionMap());
       }
     }
   }
 }
Exemplo n.º 14
0
  public JSTernCompletionCollector(
      List<ICompletionProposal> proposals,
      int startOffset,
      ITernFile ternFile,
      IIDETernProject ternProject) {
    this.proposals = proposals;
    this.ternFile = ternFile;
    this.ternProject = ternProject;

    IPreferencesService preferencesService = Platform.getPreferencesService();
    IScopeContext[] lookupOrder =
        new IScopeContext[] {
          new ProjectScope(ternProject.getProject()), new InstanceScope(), new DefaultScope()
        };

    generateAnonymousFunction =
        preferencesService.getBoolean(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.GENERATE_ANONYMOUS_FUNCTION_CONTENT_ASSIST,
            true,
            lookupOrder);

    int indentSize =
        preferencesService.getInt(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.INDENT_SIZE_CONTENT_ASSIST,
            TernUIPreferenceConstants.INDENT_SIZE_CONTENT_ASSIST_DEFAULT,
            lookupOrder);
    boolean indentWithTabs =
        preferencesService.getBoolean(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.INDENT_TABS_CONTENT_ASSIST,
            TernUIPreferenceConstants.INDENT_TABS_CONTENT_ASSIST_DEFAULT,
            lookupOrder);
    indentChars = getIndentChars(indentWithTabs, indentSize);

    expandFunction =
        preferencesService.getBoolean(
            TernUIPlugin.getDefault().getBundle().getSymbolicName(),
            TernUIPreferenceConstants.EXPAND_FUNCTION_CONTENT_ASSIST,
            true,
            lookupOrder);
  }
Exemplo n.º 15
0
 /**
  * Helper method to get a single preference setting, e.g., APT_GENSRCDIR. This is a different
  * level of abstraction than the processor -A settings! The -A settings are all contained under
  * one single preference node, APT_PROCESSOROPTIONS. Use @see #getProcessorOptions(IJavaProject)
  * to get the -A settings; use @see #getOptions(IJavaProject) to get all the preference settings
  * as a map; and use this helper method to get a single preference setting.
  *
  * @param jproj the project, or null for workspace.
  * @param optionName a preference constant from @see AptPreferenceConstants.
  * @return the string value of the setting.
  */
 public static String getString(IJavaProject jproj, String optionName) {
   IPreferencesService service = Platform.getPreferencesService();
   IScopeContext[] contexts;
   if (jproj != null) {
     contexts =
         new IScopeContext[] {
           new ProjectScope(jproj.getProject()), InstanceScope.INSTANCE, DefaultScope.INSTANCE
         };
   } else {
     contexts = new IScopeContext[] {InstanceScope.INSTANCE, DefaultScope.INSTANCE};
   }
   String pluginId = null;
   if (AptPreferenceConstants.APT_PROCESSANNOTATIONS.equals(optionName)) {
     pluginId = JavaCore.PLUGIN_ID;
   } else {
     pluginId = AptPlugin.PLUGIN_ID;
   }
   return service.getString(
       pluginId, optionName, AptPreferenceConstants.DEFAULT_OPTIONS_MAP.get(optionName), contexts);
 }
Exemplo n.º 16
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    IPreferencesService prefSvc = Platform.getPreferencesService();
    if (prefSvc != null) {
      fPrefsScope = new TestScope();
      // add TestScope to the preferences lookup order
      String[] lookupOrder =
          new String[] {
            TestScope.SCOPE,
            ProjectScope.SCOPE,
            InstanceScope.SCOPE,
            ConfigurationScope.SCOPE,
            DefaultScope.SCOPE
          };

      for (String qualifier : fQualifiers) {
        prefSvc.setDefaultLookupOrder(qualifier, null, lookupOrder);
      }
    }
  }
  /**
   * Generates connection string using user preferences
   *
   * @param dbPath Path to the database files
   * @return
   */
  private String getConnectionString(IPath dbPath) {

    IPreferencesService preferencesService = Platform.getPreferencesService();

    StringBuilder buf = new StringBuilder("jdbc:h2:").append(dbPath.append(DB_NAME).toOSString());

    buf.append(";UNDO_LOG=0");
    buf.append(";LOCK_MODE=")
        .append(
            preferencesService.getInt(
                SymfonyIndex.PLUGIN_ID, SymfonyIndexPreferences.DB_LOCK_MODE, 0, null));

    buf.append(";CACHE_TYPE=")
        .append(
            preferencesService.getString(
                SymfonyIndex.PLUGIN_ID, SymfonyIndexPreferences.DB_CACHE_TYPE, null, null));

    buf.append(";CACHE_SIZE=")
        .append(
            preferencesService.getInt(
                SymfonyIndex.PLUGIN_ID, SymfonyIndexPreferences.DB_CACHE_SIZE, 0, null));

    return buf.toString();
  }
 /**
  * This method should not intended to be used anywhere outside this class. This will be made
  * private once the deprecated J2EEPreferences class is deleted
  */
 static String getString(String name) {
   IPreferencesService preferencesService = Platform.getPreferencesService();
   IScopeContext[] lookupOrder = new IScopeContext[] {new InstanceScope(), new DefaultScope()};
   return preferencesService.getString(
       J2EEPlugin.PLUGIN_ID, name, Defaults.STRING_DEFAULT_DEFAULT, lookupOrder);
 }
Exemplo n.º 19
0
 /** @return default list max size */
 public static int getDefaultMaxResults() {
   final IPreferencesService service = Platform.getPreferencesService();
   if (service == null) return 100; // default
   return service.getInt(Activator.PLUGIN_ID, DEFAULT_MAX_RESULTS, 10, null);
 }
Exemplo n.º 20
0
 /**
  * @param setting Preference identifier
  * @param default_value Default value when preferences unavailable
  * @return String from preference system, or <code>null</code>
  */
 private static String getString(final String setting, final String default_value) {
   final IPreferencesService service = Platform.getPreferencesService();
   if (service == null) return default_value;
   return service.getString(Activator.PLUGIN_ID, setting, default_value, null);
 }
Exemplo n.º 21
0
  @Override
  public void run(final IAction action) {
    TITANDebugConsole.println("Add import called: ");
    if (targetEditor == null || !(targetEditor instanceof TTCN3Editor)) {
      return;
    }

    targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(null);

    IFile file = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
    if (file == null) {
      targetEditor
          .getEditorSite()
          .getActionBars()
          .getStatusLineManager()
          .setErrorMessage(FILENOTIDENTIFIABLE);
      return;
    }

    if (!TITANNature.hasTITANNature(file.getProject())) {
      targetEditor
          .getEditorSite()
          .getActionBars()
          .getStatusLineManager()
          .setErrorMessage(TITANNature.NO_TITAN_FILE_NATURE_FOUND);
      return;
    }

    IPreferencesService prefs = Platform.getPreferencesService();
    boolean reportDebugInformation =
        prefs.getBoolean(
            ProductConstants.PRODUCT_ID_DESIGNER,
            PreferenceConstants.DISPLAYDEBUGINFORMATION,
            true,
            null);

    int offset;
    if (!selection.isEmpty()
        && selection instanceof TextSelection
        && !"".equals(((TextSelection) selection).getText())) {
      if (reportDebugInformation) {
        TITANDebugConsole.println("text selected: " + ((TextSelection) selection).getText());
      }
      TextSelection tSelection = (TextSelection) selection;
      offset = tSelection.getOffset() + tSelection.getLength();
    } else {
      offset = ((TTCN3Editor) targetEditor).getCarretOffset();
    }

    DeclarationCollector declarationCollector =
        OpenDeclarationHelper.findVisibleDeclarations(
            targetEditor,
            new TTCN3ReferenceParser(false),
            ((TTCN3Editor) targetEditor).getDocument(),
            offset,
            false);

    if (declarationCollector == null) {
      return;
    }

    List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
    if (collected.isEmpty()) {
      // FIXME add semantic check guard on project level.
      ProjectSourceParser projectSourceParser =
          GlobalParser.getProjectSourceParser(file.getProject());
      if (reportDebugInformation) {
        TITANDebugConsole.println("No visible elements found");
      }
      for (String moduleName2 : projectSourceParser.getKnownModuleNames()) {
        Module module2 = projectSourceParser.getModuleByName(moduleName2);
        if (module2 != null) {
          // Visit each file in the project one by
          // one instead of
          // "module2.getAssignments().addDeclaration(declarationCollector)".
          Assignments assignments = module2.getAssignments();
          for (int i = 0; i < assignments.getNofAssignments(); i++) {
            assignments.getAssignmentByIndex(i).addDeclaration(declarationCollector, 0);
          }
        }
      }

      if (declarationCollector.getCollectionSize() == 0) {
        targetEditor
            .getEditorSite()
            .getActionBars()
            .getStatusLineManager()
            .setErrorMessage(NOTTTCN3DECLARATION);
        return;
      }

      if (reportDebugInformation) {
        TITANDebugConsole.println("Elements were only found in not visible modules");
      }

      DeclarationCollectionHelper resultToInsert = null;
      if (collected.size() == 1) {
        resultToInsert = collected.get(0);
      } else {
        OpenDeclarationLabelProvider labelProvider = new OpenDeclarationLabelProvider();
        ElementListSelectionDialog dialog =
            new ElementListSelectionDialog(new Shell(Display.getDefault()), labelProvider);
        dialog.setTitle("Add Import");
        dialog.setMessage("Choose element to generate an import statement for.");
        dialog.setElements(collected.toArray());
        if (dialog.open() == Window.OK) {
          if (reportDebugInformation) {
            TITANDebugConsole.getConsole()
                .newMessageStream()
                .println("Selected: " + dialog.getFirstResult());
          }
          resultToInsert = (DeclarationCollectionHelper) dialog.getFirstResult();
        }
      }

      if (resultToInsert == null) {
        return;
      }

      IFile newfile = (IFile) resultToInsert.location.getFile();
      String moduleName = projectSourceParser.containedModule(newfile);
      Module newModule = projectSourceParser.getModuleByName(moduleName);
      if (newModule == null) {
        targetEditor
            .getEditorSite()
            .getActionBars()
            .getStatusLineManager()
            .setErrorMessage("Could not identify the module in file " + newfile.getName());
        return;
      }

      String ttcnName = newModule.getIdentifier().getTtcnName();
      TITANDebugConsole.println("the new module to insert: " + ttcnName);

      final IFile actualFile = (IFile) targetEditor.getEditorInput().getAdapter(IFile.class);
      String actualModuleName = projectSourceParser.containedModule(actualFile);
      Module actualModule = projectSourceParser.getModuleByName(actualModuleName);

      int insertionOffset =
          ((TTCN3Module) actualModule).getAssignmentsScope().getLocation().getOffset() + 1;

      MultiTextEdit multiEdit = new MultiTextEdit(insertionOffset, 0);
      RewriteSessionEditProcessor processor =
          new RewriteSessionEditProcessor(
              ((TTCN3Editor) targetEditor).getDocument(),
              multiEdit,
              TextEdit.UPDATE_REGIONS | TextEdit.CREATE_UNDO);
      multiEdit.addChild(new InsertEdit(insertionOffset, "\nimport from " + ttcnName + " all;\n"));

      try {
        processor.performEdits();
      } catch (BadLocationException e) {
        ErrorReporter.logExceptionStackTrace(e);
      }
    } else {
      if (reportDebugInformation) {
        for (DeclarationCollectionHelper foundDeclaration : collected) {
          TITANDebugConsole.println(
              "declaration:"
                  + foundDeclaration.location.getFile()
                  + ": "
                  + foundDeclaration.location.getOffset()
                  + " - "
                  + foundDeclaration.location.getEndOffset()
                  + " is available");
        }
      }
    }

    Display.getDefault()
        .asyncExec(
            new Runnable() {
              @Override
              public void run() {
                MessageDialog.openWarning(
                    new Shell(Display.getDefault()),
                    "Study feature",
                    "Adding a missing importation is still under study");
              }
            });
  }
Exemplo n.º 22
0
  /**
   * Returns an integer preference for the given preference id.
   *
   * @param prefId the preference id
   * @return the integer result
   */
  public static int getInt(String prefId) {

    IPreferencesService prefs = Platform.getPreferencesService();
    return prefs.getInt(CheckstylePlugin.PLUGIN_ID, prefId, 0, null);
  }
Exemplo n.º 23
0
  /**
   * Returns a boolean preference for the given preference id.
   *
   * @param prefId the preference id
   * @return the boolean result
   */
  public static boolean getBoolean(String prefId) {

    IPreferencesService prefs = Platform.getPreferencesService();
    return prefs.getBoolean(CheckstylePlugin.PLUGIN_ID, prefId, false, null);
  }