예제 #1
0
    public void saveFilters(LogFilter[] filters) {
      StringBuilder sb = new StringBuilder();
      for (LogFilter f : filters) {
        String filterString = f.toString();
        sb.append(filterString);
        sb.append('|');
      }

      DdmsPlugin.getDefault().getPreferenceStore().setValue(PREFS_FILTERS, sb.toString());
    }
예제 #2
0
 void openFile(IFile file, IMarker marker) {
   try {
     IWorkbenchPage page = getViewSite().getWorkbenchWindow().getActivePage();
     if (page != null) {
       IDE.openEditor(page, marker);
       marker.delete();
     }
   } catch (CoreException e) {
     Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
     DdmsPlugin.getDefault().getLog().log(s);
   }
 }
예제 #3
0
  void goToErrorLine(String choice) {
    try {
      String msg = mLogPanel.getSelectedErrorLineMessage();
      if (msg != null) {
        String error_line_matcher_string = "\\s*at\\ (.*)\\((.*)\\.java\\:(\\d+)\\)";
        Matcher error_line_matcher = Pattern.compile(error_line_matcher_string).matcher(msg);

        if (error_line_matcher.find()) {
          String class_name_method = error_line_matcher.group(1);

          // TODO: Search currently only matches the class declaration (using
          // IJavaSearchConstants.DECLARATIONS). We may want to jump to the
          // "reference" of the class instead (IJavaSearchConstants.REFERENCES)
          // using the filename and line number to disambiguate the search results.
          String class_name_line = error_line_matcher.group(2);
          int line_number = Integer.parseInt(error_line_matcher.group(3));

          SearchEngine se = new SearchEngine();
          if (CHOICE_ERROR_LINE.equals(choice)) {
            se.search(
                SearchPattern.createPattern(
                    class_name_line,
                    IJavaSearchConstants.CLASS,
                    IJavaSearchConstants.DECLARATIONS,
                    SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE),
                new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
                SearchEngine.createWorkspaceScope(),
                new LogCatViewSearchRequestor(CHOICE_ERROR_LINE, line_number),
                new NullProgressMonitor());
          } else if (CHOICE_METHOD_DECLARATION.equals(choice)) {
            se.search(
                SearchPattern.createPattern(
                    class_name_method,
                    IJavaSearchConstants.METHOD,
                    IJavaSearchConstants.DECLARATIONS,
                    SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE),
                new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
                SearchEngine.createWorkspaceScope(),
                new LogCatViewSearchRequestor(CHOICE_METHOD_DECLARATION, 0),
                new NullProgressMonitor());
          }
        }
      }
    } catch (Exception e) {
      Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
      DdmsPlugin.getDefault().getLog().log(s);
    }
  }
예제 #4
0
  @Override
  public void createPartControl(Composite parent) {
    parent.setLayout(new FillLayout());

    IPreferenceStore prefStore = DdmsPlugin.getDefault().getPreferenceStore();
    mLogCatPanel = new LogCatPanel(prefStore);
    mLogCatPanel.createPanel(parent);
    setSelectionDependentPanel(mLogCatPanel);

    mLogCatPanel.addLogCatMessageSelectionListener(
        new ILogCatMessageSelectionListener() {
          @Override
          public void messageDoubleClicked(LogCatMessage m) {
            onDoubleClick(m);
          }
        });

    mClipboard = new Clipboard(parent.getDisplay());
    IActionBars actionBars = getViewSite().getActionBars();
    actionBars.setGlobalActionHandler(
        ActionFactory.COPY.getId(),
        new Action(Messages.LogCatView_Copy) {
          @Override
          public void run() {
            mLogCatPanel.copySelectionToClipboard(mClipboard);
          }
        });

    actionBars.setGlobalActionHandler(
        ActionFactory.SELECT_ALL.getId(),
        new Action(Messages.LogCatView_Select_All) {
          @Override
          public void run() {
            mLogCatPanel.selectAll();
          }
        });

    actionBars.setGlobalActionHandler(
        ActionFactory.FIND.getId(),
        new Action("Find") {
          @Override
          public void run() {
            mLogCatPanel.showFindDialog();
          }
        });
  }
예제 #5
0
  private void onDoubleClick(LogCatMessage m) {
    String msg = m.getMessage();
    if (!mStackTraceParser.isValidExceptionTrace(msg)) {
      return;
    }

    IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
    String perspectiveId = null;
    if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
      perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
    }

    String fileName = mStackTraceParser.getFileName(msg);
    int lineNumber = mStackTraceParser.getLineNumber(msg);
    String methodName = mStackTraceParser.getMethodName(msg);
    JavaSourceRevealer.revealMethod(methodName, fileName, lineNumber, perspectiveId);
  }
예제 #6
0
 void switchPerspective() {
   IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
   if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
     IWorkbench workbench = PlatformUI.getWorkbench();
     IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
     IPerspectiveRegistry perspectiveRegistry = workbench.getPerspectiveRegistry();
     String perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
     if (perspectiveId != null
         && perspectiveId.length() > 0
         && perspectiveRegistry.findPerspectiveWithId(perspectiveId) != null) {
       try {
         workbench.showPerspective(perspectiveId, window);
       } catch (WorkbenchException e) {
         e.printStackTrace();
       }
     }
   }
 }
예제 #7
0
 IMarker createMarkerFromSearchMatch(IFile file, SearchMatch match) {
   IMarker marker = null;
   try {
     if (CHOICE_METHOD_DECLARATION.equals(mChoice)) {
       HashMap<String, Object> map = new HashMap<String, Object>();
       map.put(IMarker.CHAR_START, new Integer(match.getOffset()));
       map.put(IMarker.CHAR_END, new Integer(match.getOffset() + match.getLength()));
       marker = file.createMarker(IMarker.TEXT);
       marker.setAttributes(map);
     } else if (CHOICE_ERROR_LINE.equals(mChoice)) {
       marker = file.createMarker(IMarker.TEXT);
       marker.setAttribute(IMarker.LINE_NUMBER, mLineNumber);
     }
   } catch (CoreException e) {
     Status s = new Status(Status.ERROR, DdmsPlugin.PLUGIN_ID, e.getMessage(), e);
     DdmsPlugin.getDefault().getLog().log(s);
   }
   return marker;
 }
예제 #8
0
    public LogFilter[] getFilterFromStore() {
      String filterPrefs = DdmsPlugin.getDefault().getPreferenceStore().getString(PREFS_FILTERS);

      // split in a string per filter
      String[] filters = filterPrefs.split("\\|"); // $NON-NLS-1$

      ArrayList<LogFilter> list = new ArrayList<LogFilter>(filters.length);

      for (String f : filters) {
        if (f.length() > 0) {
          LogFilter logFilter = new LogFilter();
          if (logFilter.loadFromString(f)) {
            list.add(logFilter);
          }
        }
      }

      return list.toArray(new LogFilter[list.size()]);
    }
예제 #9
0
 void goToErrorLine() {
   IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
   String value = store.getString(PreferenceInitializer.ATTR_LOGCAT_GOTO_PROBLEM);
   goToErrorLine(value);
 }
예제 #10
0
  @Override
  public void createPartControl(Composite parent) {
    Display d = parent.getDisplay();
    LogColors colors = new LogColors();

    ImageLoader loader = ImageLoader.getDdmUiLibLoader();

    colors.infoColor = new Color(d, 0, 127, 0);
    colors.debugColor = new Color(d, 0, 0, 127);
    colors.errorColor = new Color(d, 255, 0, 0);
    colors.warningColor = new Color(d, 255, 127, 0);
    colors.verboseColor = new Color(d, 0, 0, 0);

    mCreateFilterAction =
        new CommonAction("Create Filter") {
          @Override
          public void run() {
            mLogPanel.addFilter();
          }
        };
    mCreateFilterAction.setToolTipText("Create Filter");
    mCreateFilterAction.setImageDescriptor(loader.loadDescriptor("add.png"));

    mEditFilterAction =
        new CommonAction("Edit Filter") {
          @Override
          public void run() {
            mLogPanel.editFilter();
          }
        };
    mEditFilterAction.setToolTipText("Edit Filter");
    mEditFilterAction.setImageDescriptor(loader.loadDescriptor("edit.png")); // $NON-NLS-1$

    mDeleteFilterAction =
        new CommonAction("Delete Filter") {
          @Override
          public void run() {
            mLogPanel.deleteFilter();
          }
        };
    mDeleteFilterAction.setToolTipText("Delete Filter");
    mDeleteFilterAction.setImageDescriptor(loader.loadDescriptor("delete.png")); // $NON-NLS-1$

    mExportAction =
        new CommonAction("Export Selection As Text...") {
          @Override
          public void run() {
            mLogPanel.save();
          }
        };
    mExportAction.setToolTipText("Export Selection As Text...");
    mExportAction.setImageDescriptor(loader.loadDescriptor("save.png")); // $NON-NLS-1$

    mGotoMethodDeclarationAction =
        new CommonAction("Go to Problem (method declaration)") {
          @Override
          public void run() {
            goToErrorLine(CHOICE_METHOD_DECLARATION);
          }
        };

    mGotoErrorLineAction =
        new CommonAction("Go to Problem (error line)") {
          @Override
          public void run() {
            goToErrorLine(CHOICE_ERROR_LINE);
          }
        };

    LogLevel[] levels = LogLevel.values();
    mLogLevelActions = new CommonAction[mLogLevelIcons.length];
    for (int i = 0; i < mLogLevelActions.length; i++) {
      String name = levels[i].getStringValue();
      mLogLevelActions[i] =
          new CommonAction(name, IAction.AS_CHECK_BOX) {
            @Override
            public void run() {
              // disable the other actions and record current index
              for (int i = 0; i < mLogLevelActions.length; i++) {
                Action a = mLogLevelActions[i];
                if (a == this) {
                  a.setChecked(true);

                  // set the log level
                  mLogPanel.setCurrentFilterLogLevel(i + 2);
                } else {
                  a.setChecked(false);
                }
              }
            }
          };

      mLogLevelActions[i].setToolTipText(name);
      mLogLevelActions[i].setImageDescriptor(loader.loadDescriptor(mLogLevelIcons[i]));
    }

    mClearAction =
        new Action("Clear Log") {
          @Override
          public void run() {
            mLogPanel.clear();
          }
        };
    mClearAction.setImageDescriptor(loader.loadDescriptor("clear.png")); // $NON-NLS-1$

    // now create the log view
    mLogPanel = new LogPanel(colors, new FilterStorage(), LogPanel.FILTER_MANUAL);
    mLogPanel.setLogCatViewInterface(this);
    mLogPanel.setActions(mDeleteFilterAction, mEditFilterAction, mLogLevelActions);

    // get the font
    String fontStr =
        DdmsPlugin.getDefault()
            .getPreferenceStore()
            .getString(PreferenceInitializer.ATTR_LOGCAT_FONT);
    if (fontStr != null) {
      FontData data = new FontData(fontStr);

      if (fontStr != null) {
        mLogPanel.setFont(new Font(parent.getDisplay(), data));
      }
    }

    mLogPanel.createPanel(parent);
    setSelectionDependentPanel(mLogPanel);

    // place the actions.
    placeActions();

    // setup the copy action
    mClipboard = new Clipboard(d);
    IActionBars actionBars = getViewSite().getActionBars();
    actionBars.setGlobalActionHandler(
        ActionFactory.COPY.getId(),
        new Action("Copy") {
          @Override
          public void run() {
            mLogPanel.copy(mClipboard);
          }
        });

    // setup the select all action
    actionBars.setGlobalActionHandler(
        ActionFactory.SELECT_ALL.getId(),
        new Action("Select All") {
          @Override
          public void run() {
            mLogPanel.selectAll();
          }
        });
  }