Ejemplo n.º 1
0
 private EditorTextHoverDescriptor[] initializeEditorTextHoverDescriprtors(
     IPreferenceStore store, String natureId) {
   EditorTextHoverDescriptor[] descriptors =
       EditorTextHoverDescriptor.getContributedHovers(natureId, store);
   ConfigurationElementSorter sorter =
       new ConfigurationElementSorter() {
         /*
          * @see org.eclipse.ui.texteditor.ConfigurationElementSorter#
          * getConfigurationElement(java.lang.Object)
          */
         public IConfigurationElement getConfigurationElement(Object object) {
           return ((EditorTextHoverDescriptor) object).getConfigurationElement();
         }
       };
   sorter.sort(descriptors);
   // Move Best Match hover to front
   for (int i = 0; i < descriptors.length - 1; i++) {
     if (PreferenceConstants.ID_BESTMATCH_HOVER.equals(descriptors[i].getId())) {
       final EditorTextHoverDescriptor hoverDescriptor = descriptors[i];
       for (int j = i; j > 0; j--) descriptors[j] = descriptors[j - 1];
       descriptors[0] = hoverDescriptor;
       break;
     }
   }
   return descriptors;
 }
  private void restoreFromPreferences() {

    String compiledTextHoverModifiers =
        fStore.getString(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS);

    StringTokenizer tokenizer =
        new StringTokenizer(compiledTextHoverModifiers, EditorTextHoverDescriptor.VALUE_SEPARATOR);
    HashMap idToModifier = new HashMap(tokenizer.countTokens() / 2);

    while (tokenizer.hasMoreTokens()) {
      String id = tokenizer.nextToken();
      if (tokenizer.hasMoreTokens()) idToModifier.put(id, tokenizer.nextToken());
    }

    String compiledTextHoverModifierMasks =
        DLTKUIPlugin.getDefault()
            .getPreferenceStore()
            .getString(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS);

    tokenizer =
        new StringTokenizer(
            compiledTextHoverModifierMasks, EditorTextHoverDescriptor.VALUE_SEPARATOR);
    HashMap idToModifierMask = new HashMap(tokenizer.countTokens() / 2);

    while (tokenizer.hasMoreTokens()) {
      String id = tokenizer.nextToken();
      if (tokenizer.hasMoreTokens()) idToModifierMask.put(id, tokenizer.nextToken());
    }

    for (int i = 0; i < fHoverConfigs.length; i++) {
      String modifierString = (String) idToModifier.get(getContributedHovers()[i].getId());
      boolean enabled = true;
      if (modifierString == null) modifierString = EditorTextHoverDescriptor.DISABLED_TAG;

      if (modifierString.startsWith(EditorTextHoverDescriptor.DISABLED_TAG)) {
        enabled = false;
        modifierString = modifierString.substring(1);
      }

      if (modifierString.equals(EditorTextHoverDescriptor.NO_MODIFIER))
        modifierString = ""; // $NON-NLS-1$

      fHoverConfigs[i].fModifierString = modifierString;
      fHoverConfigs[i].fIsEnabled = enabled;
      fHoverConfigs[i].fStateMask = EditorTextHoverDescriptor.computeStateMask(modifierString);

      if (fHoverConfigs[i].fStateMask == -1) {
        try {
          fHoverConfigs[i].fStateMask =
              Integer.parseInt((String) idToModifierMask.get(getContributedHovers()[i].getId()));
        } catch (NumberFormatException ex) {
          fHoverConfigs[i].fStateMask = -1;
        }
      }
    }
  }
  private void handleModifierModified() {
    int i = fHoverTable.getSelectionIndex();
    if (i == -1) return;

    String modifiers = fModifierEditor.getText();
    fHoverConfigs[i].fModifierString = modifiers;
    fHoverConfigs[i].fStateMask = EditorTextHoverDescriptor.computeStateMask(modifiers);

    // update table
    fHoverTableViewer.refresh(getContributedHovers()[i]);

    updateStatus(fHoverConfigs[i]);
  }