/**
   * Invoke content assist on the given viewer at the given offset, for the given number of pages
   * and return the results of each page
   *
   * @param viewer
   * @param offset
   * @param pageCount
   * @return
   * @throws Exception
   */
  private static ICompletionProposal[][] getProposals(
      StructuredTextViewer viewer, int offset, int pageCount) throws Exception {
    // setup the viewer
    StructuredTextViewerConfigurationHTML configuration =
        new StructuredTextViewerConfigurationHTML();
    ContentAssistant contentAssistant =
        (ContentAssistant) configuration.getContentAssistant(viewer);
    viewer.configure(configuration);
    viewer.setSelectedRange(offset, 0);

    // get the processor
    String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
    IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);

    // fire content assist session about to start
    Method privateFireSessionBeginEventMethod =
        ContentAssistant.class.getDeclaredMethod(
            "fireSessionBeginEvent", new Class[] {boolean.class});
    privateFireSessionBeginEventMethod.setAccessible(true);
    privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] {Boolean.TRUE});

    // get content assist suggestions
    ICompletionProposal[][] pages = new ICompletionProposal[pageCount][];
    for (int p = 0; p < pageCount; ++p) {
      pages[p] = processor.computeCompletionProposals(viewer, offset);
    }

    // fire content assist session ending
    Method privateFireSessionEndEventMethod =
        ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
    privateFireSessionEndEventMethod.setAccessible(true);
    privateFireSessionEndEventMethod.invoke(contentAssistant, null);

    return pages;
  }
 public int getCaretOffset() {
   StructuredTextViewer stv = fTextEditor.getTextViewer();
   if ((stv != null) && (stv.getTextWidget() != null) && !stv.getTextWidget().isDisposed()) {
     return stv.widgetOffset2ModelOffset(stv.getTextWidget().getCaretOffset());
   }
   return 0;
 }
  /**
   * Run a proposal test by opening the given file and invoking content assist for each expected
   * proposal count at the given line number and line character offset and then compare the number
   * of proposals for each invocation (pages) to the expected number of proposals.
   *
   * @param fileName
   * @param lineNum
   * @param lineRelativeCharOffset
   * @param expectedProposalCounts
   * @throws Exception
   */
  private static void runProposalTest(
      String fileName, int lineNum, int lineRelativeCharOffset, int[] expectedProposalCounts)
      throws Exception {

    IFile file = getFile(fileName);
    StructuredTextEditor editor = getEditor(file);
    StructuredTextViewer viewer = editor.getTextViewer();
    int offset = viewer.getDocument().getLineOffset(lineNum) + lineRelativeCharOffset;

    ICompletionProposal[][] pages = getProposals(viewer, offset, expectedProposalCounts.length);

    verifyProposalCounts(pages, expectedProposalCounts);
  }
예제 #4
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets
  * .Composite)
  */
 @Override
 public void createPartControl(Composite parent) {
   int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION;
   fSourceViewer = new StructuredTextViewer(parent, null, null, false, styles);
   fSourceViewer.setEditable(false);
   fSourceViewer.configure(new StructuredTextViewerConfigurationHTML());
   getSite()
       .getWorkbenchWindow()
       .getSelectionService()
       .addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW, this);
   getSite().setSelectionProvider(fSourceViewer.getSelectionProvider());
   setBackgroundColor();
   fTerminateListener =
       new IDebugEventSetListener() {
         public void handleDebugEvents(DebugEvent[] events) {
           if (events != null) {
             int size = events.length;
             for (int i = 0; i < size; i++) {
               Object obj = events[i].getSource();
               if (!(obj instanceof IPHPDebugTarget || obj instanceof PHPThread)) continue;
               if (events[i].getKind() == DebugEvent.TERMINATE
                   || events[i].getKind() == DebugEvent.SUSPEND) {
                 final IPHPDebugTarget target;
                 if (obj instanceof IPHPDebugTarget) {
                   target = (IPHPDebugTarget) obj;
                 } else {
                   target = (IPHPDebugTarget) ((PHPThread) obj).getDebugTarget();
                 }
                 Job job =
                     new UIJob(PHPDebugUIMessages.PHPDebugUIPlugin_1) {
                       public IStatus runInUIThread(IProgressMonitor monitor) {
                         update(target);
                         return Status.OK_STATUS;
                       }
                     };
                 job.schedule();
               }
             }
           }
         }
       };
   DebugPlugin.getDefault().addDebugEventListener(fTerminateListener);
   if (fPartListener == null) {
     fPartListener = new DebugViewPartListener();
     getSite().getPage().addPartListener(fPartListener);
   }
 }
예제 #5
0
 private void setBackgroundColor() {
   IPreferenceStore store = EditorsPlugin.getDefault().getPreferenceStore();
   fSourceViewer.getTextWidget().setBackground(getBackgroundColor(store));
   if (fPropertyChangeListener == null) {
     fPropertyChangeListener =
         new IPropertyChangeListener() {
           public void propertyChange(PropertyChangeEvent event) {
             IPreferenceStore store = EditorsPlugin.getDefault().getPreferenceStore();
             String prop = event.getProperty();
             if (prop.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
                 || prop.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)) {
               if (fSourceViewer == null
                   || fSourceViewer.getTextWidget() == null
                   || fSourceViewer.getTextWidget().isDisposed()) {
                 return;
               }
               fSourceViewer.getTextWidget().setBackground(getBackgroundColor(store));
             }
           }
         };
     store.addPropertyChangeListener(fPropertyChangeListener);
   }
 }