Пример #1
0
 public static void logErrorStatus(String message, IStatus status) {
   if (status == null) {
     DLTKUIPlugin.logErrorMessage(message);
     return;
   }
   MultiStatus multi =
       new MultiStatus(DLTKUIPlugin.PLUGIN_ID, IDLTKStatusConstants.INTERNAL_ERROR, message, null);
   multi.add(status);
   DLTKUIPlugin.log(multi);
 }
    @Override
    public Image getImage(Object element) {

      if (element instanceof GetterSetterEntry) {
        return DLTKUIPlugin.getImageDescriptorRegistry().get(DLTKPluginImages.DESC_FIELD_PUBLIC);
      } else if (element instanceof IField) {
        return DLTKUIPlugin.getImageDescriptorRegistry().get(DLTKPluginImages.DESC_FIELD_PRIVATE);
      }
      return super.getImage(element);
    }
 /*
  * @see StructuredViewer#handleInvalidSelection(ISelection, ISelection)
  */
 protected void handleInvalidSelection(ISelection invalidSelection, ISelection newSelection) {
   // on change of input, try to keep selected methods stable by selecting a method with the same
   // signature: See #5466
   List oldSelections = SelectionUtil.toList(invalidSelection);
   List newSelections = SelectionUtil.toList(newSelection);
   if (!oldSelections.isEmpty()) {
     ArrayList newSelectionElements = new ArrayList(newSelections);
     try {
       Object[] currElements = getFilteredChildren(getInput());
       for (int i = 0; i < oldSelections.size(); i++) {
         Object curr = oldSelections.get(i);
         if (curr instanceof IMethod && !newSelections.contains(curr)) {
           IMethod method = (IMethod) curr;
           if (method.exists()) {
             IMethod similar = findSimilarMethod(method, currElements);
             if (similar != null) {
               newSelectionElements.add(similar);
             }
           }
         }
       }
       if (!newSelectionElements.isEmpty()) {
         newSelection = new StructuredSelection(newSelectionElements);
       } else if (currElements.length > 0) {
         newSelection = new StructuredSelection(currElements[0]);
       }
     } catch (ModelException e) {
       DLTKUIPlugin.log(e);
     }
   }
   setSelection(newSelection);
   updateSelection(newSelection);
 }
Пример #4
0
 public static Shell getActiveWorkbenchShell() {
   IWorkbenchWindow window = DLTKUIPlugin.getActiveWorkbenchWindow();
   if (window != null) {
     return window.getShell();
   }
   return null;
 }
 /**
  * Creates a new content provider for Java elements.
  *
  * @param provideMembers if set, members of compilation units and class files are shown
  */
 public ScriptExplorerContentProvider(final boolean provideMembers) {
   super(provideMembers);
   fShowLibrariesNode = false;
   fIsFlatLayout = false;
   fFoldPackages = arePackagesFoldedInHierarchicalLayout();
   fPendingUpdates = null;
   DLTKUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
 }
 public TestScriptCommentScanner(
     String[] tags, String commentKey, String todoKey, boolean caseSensitive) {
   super(
       new DLTKColorManager(true),
       DLTKUIPlugin.getDefault().getPreferenceStore(),
       commentKey,
       todoKey,
       new TestTodoTaskPreferences(tags, caseSensitive));
 }
Пример #7
0
 public static void logErrorMessage(String message, Throwable throwable) {
   DLTKUIPlugin.log(
       new Status(
           IStatus.ERROR,
           DLTKUIPlugin.PLUGIN_ID,
           IDLTKStatusConstants.INTERNAL_ERROR,
           message,
           throwable));
 }
Пример #8
0
 public static void log(Throwable e) {
   DLTKUIPlugin.log(
       new Status(
           IStatus.ERROR,
           DLTKUIPlugin.PLUGIN_ID,
           IDLTKStatusConstants.INTERNAL_ERROR,
           DLTKUIMessages.ScriptPlugin_internal_error,
           e));
 }
  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;
        }
      }
    }
  }
 public void setLinkingEnabled(boolean enabled) {
   fLinkingEnabled = enabled;
   DLTKUIPlugin.getDefault().getPreferenceStore().setValue(getLinkToEditorKey(), enabled);
   if (enabled) {
     IEditorPart editor = getSite().getPage().getActiveEditor();
     if (editor != null) {
       setSelectionFromEditor(editor);
     }
   }
 }
Пример #11
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   synchronized (getClass()) {
     if (monitor.isCanceled()) {
       return Status.CANCEL_STATUS;
     }
     Job[] buildJobs = Job.getJobManager().find(ResourcesPlugin.FAMILY_MANUAL_BUILD);
     for (int i = 0; i < buildJobs.length; i++) {
       Job curr = buildJobs[i];
       if (curr != this && curr instanceof BuildJob) {
         BuildJob job = (BuildJob) curr;
         if (job.isCoveredBy(this)) {
           curr.cancel(); // cancel all other build jobs of
           // our kind
         }
       }
     }
   }
   try {
     if (fProject != null) {
       monitor.beginTask(
           Messages.format(DLTKUIMessages.CoreUtility_buildproject_taskname, fProject.getName()),
           2);
       fProject.build(IncrementalProjectBuilder.FULL_BUILD, new SubProgressMonitor(monitor, 1));
       DLTKUIPlugin.getWorkspace()
           .build(
               IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(monitor, 1));
     } else {
       monitor.beginTask(DLTKUIMessages.CoreUtility_buildall_taskname, 2);
       DLTKUIPlugin.getWorkspace()
           .build(IncrementalProjectBuilder.FULL_BUILD, new SubProgressMonitor(monitor, 2));
     }
   } catch (CoreException e) {
     return e.getStatus();
   } catch (OperationCanceledException e) {
     return Status.CANCEL_STATUS;
   } finally {
     monitor.done();
   }
   return Status.OK_STATUS;
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface
   * .action.IMenuManager)
   */
  public void menuAboutToShow(IMenuManager menu) {
    DLTKUIPlugin.createStandardGroups(menu);

    IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection();
    int size = selection.size();
    Object element = selection.getFirstElement();

    if (size == 1) addOpenNewWindowAction(menu, element);
    fActionGroups.setContext(new ActionContext(selection));
    fActionGroups.fillContextMenu(menu);
    fActionGroups.setContext(null);
  }
Пример #13
0
  static void setReadOnly(IResource resource, boolean readOnly) {
    ResourceAttributes resourceAttributes = resource.getResourceAttributes();
    if (resourceAttributes == null) // not supported on this platform for this resource
    return;

    resourceAttributes.setReadOnly(readOnly);
    try {
      resource.setResourceAttributes(resourceAttributes);
    } catch (CoreException e) {
      DLTKUIPlugin.log(e);
    }
  }
 /** Copy of super method, but returning a custom TemplateInformationControlCreator */
 @Override
 protected IInformationControlCreator getInformationControlCreator() {
   int orientation = Window.getDefaultOrientation();
   IEditorPart editor = getContext().getEditor();
   if (editor == null) editor = DLTKUIPlugin.getActivePage().getActiveEditor();
   if (editor instanceof IWorkbenchPartOrientation)
     orientation = ((IWorkbenchPartOrientation) editor).getOrientation();
   IDLTKLanguageToolkit toolkit = null;
   toolkit = DLTKLanguageManager.getLanguageToolkit(getContext().getLanguageNatureID());
   if ((toolkit == null) && (editor instanceof ScriptEditor))
     toolkit = ((ScriptEditor) editor).getLanguageToolkit();
   return new LuaTemplateInformationControlCreator(orientation, toolkit);
 }
Пример #15
0
  public void install(IValidationContext helper) {

    IEditorInput fEditorInput = findEditor(helper);

    fDocumentProvider = DLTKUIPlugin.getDefault().getSourceModuleDocumentProvider();

    fEditor = getEditor(fEditorInput);

    fIsScriptReconcilingListener = fEditor instanceof IPhpScriptReconcilingListener;
    if (fIsScriptReconcilingListener) {
      fJavaReconcilingListener = (IPhpScriptReconcilingListener) fEditor;
    }
  }
Пример #16
0
 private void restoreLayoutState(IMemento memento) {
   if (memento == null) {
     // read state from the preference store
     IPreferenceStore store = DLTKUIPlugin.getDefault().getPreferenceStore();
     fCurrViewState = store.getInt(this.getViewSite().getId() + TAG_VIEW_STATE);
   } else {
     // restore from memento
     Integer integer = memento.getInteger(this.getViewSite().getId() + TAG_VIEW_STATE);
     if ((integer == null) || !isValidState(integer.intValue())) {
       fCurrViewState = LIST_VIEW_STATE;
     } else fCurrViewState = integer.intValue();
   }
 }
Пример #17
0
 /*
  * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
  */
 public void selectionChanged(IStructuredSelection selection) {
   if (ReorgUtils.containsOnlyProjects(selection.toList())) {
     setEnabled(createWorkbenchAction(selection).isEnabled());
     return;
   }
   try {
     setEnabled(RefactoringAvailabilityTester.isDeleteAvailable(selection.toArray()));
   } catch (CoreException e) {
     // no ui here - this happens on selection changes
     // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
     if (ScriptModelUtil.isExceptionToBeLogged(e)) DLTKUIPlugin.log(e);
     setEnabled(false);
   }
 }
Пример #18
0
  public DeleteAction(IWorkbenchSite site) {
    super(site);
    setText(ReorgMessages.DeleteAction_3);
    setDescription(ReorgMessages.DeleteAction_4);
    ISharedImages workbenchImages = DLTKUIPlugin.getDefault().getWorkbench().getSharedImages();
    setDisabledImageDescriptor(
        workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
    setImageDescriptor(workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
    setHoverImageDescriptor(workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));

    if (DLTKCore.DEBUG) {
      System.err.println("Add help support here..."); // $NON-NLS-1$
    }
  }
Пример #19
0
    public void changeControlPressed(DialogField field) {
      IEnvironment environment = getEnvironment();
      IEnvironmentUI environmentUI = (IEnvironmentUI) environment.getAdapter(IEnvironmentUI.class);
      if (environmentUI != null) {
        String selectedDirectory = environmentUI.selectFolder(getShell());

        if (selectedDirectory != null) {
          // fLocation.setText(selectedDirectory);
          DLTKUIPlugin.getDefault()
              .getDialogSettings()
              .put(DIALOGSTORE_LAST_EXTERNAL_LOC, selectedDirectory);
        }
      }
    }
Пример #20
0
  /**
   * Returns the Script content assist history.
   *
   * @return the Script content assist history
   */
  public ContentAssistHistory getContentAssistHistory() {
    if (fContentAssistHistory == null) {
      try {
        fContentAssistHistory =
            ContentAssistHistory.load(
                getPluginPreferences(), PreferenceConstants.CODEASSIST_LRU_HISTORY);
      } catch (CoreException x) {
        DLTKUIPlugin.log(x);
      }
      if (fContentAssistHistory == null) {
        fContentAssistHistory = new ContentAssistHistory();
      }
    }

    return fContentAssistHistory;
  }
  public ISourceRange getNewSelectionRange(ISourceRange oldSourceRange, IType[] types) {
    try {
      if (types == null) types = getTypes();
      Integer[] offsetArray = createOffsetArray(types);
      if (offsetArray.length == 0) return oldSourceRange;
      Arrays.sort(offsetArray);
      Integer oldOffset = new Integer(oldSourceRange.getOffset());
      int index = Arrays.binarySearch(offsetArray, oldOffset);

      if (fIsGotoNext) return createNewSourceRange(getNextOffset(index, offsetArray, oldOffset));
      else return createNewSourceRange(getPreviousOffset(index, offsetArray, oldOffset));

    } catch (ModelException e) {
      DLTKUIPlugin.log(e); // dialog would be too heavy here
      return oldSourceRange;
    }
  }
  /*
   * (non-Javadoc) Method declared on IElementChangedListener.
   */
  public void elementChanged(final ElementChangedEvent event) {
    final ArrayList<Runnable> runnables = new ArrayList<Runnable>();
    try {
      // 58952 delete project does not update Package Explorer [package
      // explorer]
      // if the input to the viewer is deleted then refresh to avoid the
      // display of stale elements
      if (inputDeleted(runnables)) {
        return;
      }

      processDelta(event.getDelta(), runnables);
    } catch (ModelException e) {
      DLTKUIPlugin.log(e);
    } finally {
      executeRunnables(runnables);
    }
  }
Пример #23
0
 /**
  * Finds and returns the Script element selected in the given part.
  *
  * @param part the workbench part for which to find the selected Script element
  * @param selection the selection
  * @return the selected Script element
  */
 protected Object findSelectedModelElement(IWorkbenchPart part, ISelection selection) {
   try {
     if (isValidWorkbenchPart(part) && selection instanceof ITextSelection) {
       final IEditorPart editor = (IEditorPart) part;
       IModelElement[] elements =
           TextSelectionConverter.codeResolve(editor, (ITextSelection) selection);
       if (elements != null && elements.length > 0) {
         return elements.length == 1 ? elements[0] : (Object) new ModelElementArray(elements);
       }
     } else if (selection instanceof IStructuredSelection) {
       Object element = SelectionUtil.getSingleElement(selection);
       return findModelElement(element);
     }
   } catch (ModelException e) {
     DLTKUIPlugin.log(e);
   }
   return null;
 }
  /**
   * @param input the editor input
   * @param offset the offset in the file
   * @return the element at the given offset
   */
  protected IModelElement getElementAt(IEditorInput input, int offset) {

    IWorkingCopyManager manager = DLTKUIPlugin.getDefault().getWorkingCopyManager();
    ISourceModule unit = manager.getWorkingCopy(input);
    if (unit != null)
      try {
        if (unit.isConsistent()) return unit.getElementAt(offset);
        else {
          /*
           * XXX: We should set the selection later when the CU is
           * reconciled. see
           * https://bugs.eclipse.org/bugs/show_bug.cgi?id=51290
           */
        }
      } catch (ModelException ex) {
        // fall through
      }
    return null;
  }
Пример #25
0
  /**
   * Returns the model element wrapped by the given editor input.
   *
   * @param editorInput the editor input
   * @return the model element wrapped by <code>editorInput</code> or <code>null</code> if none
   */
  public static ISourceModule getEditorInputModelElement(IEditorInput editorInput) {
    // Performance: check working copy manager first: this is faster
    ISourceModule je =
        DLTKUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput, false);
    if (je != null) {
      return je;
    }

    if (editorInput instanceof FileStoreEditorInput) {
      ISourceModule module = resolveSourceModule((FileStoreEditorInput) editorInput);
      if (module != null) {
        return module;
      }
    }
    IModelElement me = (IModelElement) editorInput.getAdapter(IModelElement.class);
    if (me instanceof ISourceModule) {
      return (ISourceModule) me;
    }
    return null;
  }
  public void performOk() {
    StringBuffer buf = new StringBuffer();
    StringBuffer maskBuf = new StringBuffer();
    for (int i = 0; i < fHoverConfigs.length; i++) {
      buf.append(getContributedHovers()[i].getId());
      buf.append(EditorTextHoverDescriptor.VALUE_SEPARATOR);
      if (!fHoverConfigs[i].fIsEnabled) buf.append(EditorTextHoverDescriptor.DISABLED_TAG);
      String modifier = fHoverConfigs[i].fModifierString;
      if (modifier == null || modifier.length() == 0)
        modifier = EditorTextHoverDescriptor.NO_MODIFIER;
      buf.append(modifier);
      buf.append(EditorTextHoverDescriptor.VALUE_SEPARATOR);

      maskBuf.append(getContributedHovers()[i].getId());
      maskBuf.append(EditorTextHoverDescriptor.VALUE_SEPARATOR);
      maskBuf.append(fHoverConfigs[i].fStateMask);
      maskBuf.append(EditorTextHoverDescriptor.VALUE_SEPARATOR);
    }
    fStore.setValue(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS, buf.toString());
    fStore.setValue(PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIER_MASKS, maskBuf.toString());

    DLTKUIPlugin.getDefault().resetEditorTextHoverDescriptors(fNature);
  }
Пример #27
0
  private void switchViewer(int state) {
    // Indicate which viewer is to be used
    if (fCurrViewState == state) return;
    else {
      fCurrViewState = state;
      IPreferenceStore store = DLTKUIPlugin.getDefault().getPreferenceStore();
      store.setValue(getViewSite().getId() + TAG_VIEW_STATE, state);
    }

    // get the information from the existing viewer
    StructuredViewer viewer = fWrappedViewer.getViewer();
    Object object = viewer.getInput();
    ISelection selection = viewer.getSelection();

    // create and set up the new viewer
    Control control = createViewer(fWrappedViewer.getControl().getParent()).getControl();

    setUpViewer(fWrappedViewer);

    createSelectAllAction();

    // add the selection information from old viewer
    fWrappedViewer.setViewerInput(object);
    fWrappedViewer.getControl().setFocus();
    fWrappedViewer.setSelection(selection, true);

    // dispose old viewer
    viewer.getContentProvider().dispose();
    viewer.getControl().dispose();

    // layout the new viewer
    if (control != null && !control.isDisposed()) {
      control.setVisible(true);
      control.getParent().layout(true);
    }
  }
 public ExclusionInclusionLabelProvider(ImageDescriptor descriptor) {
   ImageDescriptorRegistry registry = DLTKUIPlugin.getImageDescriptorRegistry();
   fElementImage = registry.get(descriptor);
 }
 protected ScriptUILabelProvider createLabelProvider() {
   return new AppearanceAwareLabelProvider(
       AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS,
       AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | ScriptElementImageProvider.SMALL_ICONS,
       DLTKUIPlugin.getDefault().getPreferenceStore());
 }
 private void initLinkingEnabled() {
   fLinkingEnabled =
       DLTKUIPlugin.getDefault().getPreferenceStore().getBoolean(getLinkToEditorKey());
 }