コード例 #1
0
  /**
   * use {@link GraphicalViewerKeyHandler} first if auto-layout is active handles the searching on
   * the graph (depth-first, same way as in Outline)
   */
  @Override
  public boolean keyPressed(KeyEvent e) {
    if (Character.isISOControl(e.character)) {
      if (featureModel.getLayout().hasFeaturesAutoLayout()) {
        return gvKeyHandler.keyPressed(e);
      } else {
        return super.keyPressed(e);
      }
    }

    final long currentTime = System.currentTimeMillis();
    if (currentTime - lastTime > timeoutThreshold) {
      curSearchString = "";
    }
    lastTime = currentTime;

    curIndex = updateIterator();

    if (curSearchString.length() == 1
        && curSearchString.charAt(0) == Character.toLowerCase(e.character)) {
      curSearchString = "";
      curIndex = (curIndex + 1) % featureList.size();
    }
    curSearchString += Character.toLowerCase(e.character);

    final int foundIndex = search();
    if (foundIndex >= 0) {
      // select the new feature
      final Feature curFeature = featureModel.getFeature(featureList.get(foundIndex));
      if (curFeature != null) {
        FeatureEditPart part = (FeatureEditPart) viewer.getEditPartRegistry().get(curFeature);
        viewer.setSelection(new StructuredSelection(part));
        viewer.reveal(part);
        curIndex = foundIndex;
      }
    }

    return true;
  }
コード例 #2
0
  private int updateIterator() {
    final IStructuredSelection sel = (IStructuredSelection) viewer.getSelection();

    if (sel.size() == 1 && !(sel.getFirstElement() instanceof ModelEditPart)) {
      final Object element = sel.getFirstElement();
      final String featureName;

      if (element instanceof FeatureEditPart) {
        featureName = ((FeatureEditPart) element).getFeature().getName();
      } else if (element instanceof Feature) {
        featureName = ((Feature) element).getName();
      } else {
        return 0;
      }

      return (!featureName.equalsIgnoreCase(featureList.get(curIndex)))
          ? featureList.indexOf(featureName)
          : curIndex;
    }
    return 0;
  }