Exemplo n.º 1
0
 private void removeChildren(TreePath parent) {
   for (Iterator<TreePath> i = checkedPaths.iterator(); i.hasNext(); ) {
     TreePath p = i.next();
     if (p.getParentPath() != null && parent.equals(p.getParentPath())) {
       i.remove();
     }
   }
 }
Exemplo n.º 2
0
    /** This is where the ghost image is drawn */
    public void dragOver(final DropTargetDragEvent e) {
      if ((e == null)
          || (_raGhost == null)
          || (_ptLast == null)
          || (_ptOffset == null)
          || (_imgGhost == null)
          || (_raCueLine == null)) return;
      // Even if the mouse is not moving, this method is still invoked 10 times per second
      final Point pt = e.getLocation();
      if (pt == null) return;
      if (pt.equals(_ptLast)) return;

      // Try to determine whether the user is flicking the cursor right or left
      final int nDeltaLeftRight = pt.x - _ptLast.x;
      if (((_nLeftRight > 0) && (nDeltaLeftRight < 0))
          || ((_nLeftRight < 0) && (nDeltaLeftRight > 0))) _nLeftRight = 0;
      _nLeftRight += nDeltaLeftRight;
      _ptLast = pt;
      final Graphics2D g2 = (Graphics2D) getGraphics();
      if (g2 == null) return;

      // If a drag image is not supported by the platform, then draw my own drag image
      if (!DragSource.isDragImageSupported()) {
        JDragTree.this.paintImmediately(
            _raGhost.getBounds()); // Rub out the last ghost image and cue line
        // And remember where we are about to draw the new ghost image
        _raGhost.setRect(
            pt.x - _ptOffset.x, pt.y - _ptOffset.y, _imgGhost.getWidth(), _imgGhost.getHeight());
        g2.drawImage(
            _imgGhost,
            AffineTransform.getTranslateInstance(_raGhost.getX(), _raGhost.getY()),
            null);
      } else // Just rub out the last cue line
      JDragTree.this.paintImmediately(_raCueLine.getBounds());

      final TreePath path = getClosestPathForLocation(pt.x, pt.y);
      if (!(path == _pathLast)) {
        _nLeftRight = 0; // We've moved up or down, so reset left/right movement trend
        _pathLast = path;
        _timerHover.restart();
      }

      // In any case draw (over the ghost image if necessary) a cue line indicating where a drop
      // will occur
      final Rectangle raPath = getPathBounds(path);
      _raCueLine.setRect(0, raPath.y + (int) raPath.getHeight(), getWidth(), 2);

      g2.setColor(_colorCueLine);
      g2.fill(_raCueLine);

      // And include the cue line in the area to be rubbed out next time
      _raGhost = _raGhost.createUnion(_raCueLine);

      // Do this if you want to prohibit dropping onto the drag source
      if (path.equals(_pathSource)) e.rejectDrag();
      else e.acceptDrag(e.getDropAction());
    }
Exemplo n.º 3
0
  public static void dropSelectionButUnderPoint(JTree tree, Point treePoint) {
    final TreePath toRetain = tree.getPathForLocation(treePoint.x, treePoint.y);
    if (toRetain == null) return;

    TreePath[] selection = tree.getSelectionModel().getSelectionPaths();
    selection = selection == null ? new TreePath[0] : selection;
    for (TreePath each : selection) {
      if (toRetain.equals(each)) continue;
      tree.getSelectionModel().removeSelectionPath(each);
    }
  }
Exemplo n.º 4
0
    public boolean isDropAcceptable(final DropTargetDropEvent e) {
      // Only accept COPY or MOVE gestures (ie LINK is not supported)
      if ((e.getDropAction() & DnDConstants.ACTION_MOVE) == 0) return false;

      // Only accept this particular flavor
      if (!e.isDataFlavorSupported(JDragTree.TREEPATH_FLAVOR)) return false;

      // Do this if you want to prohibit dropping onto the drag source...
      final Point pt = e.getLocation();
      final TreePath path = getClosestPathForLocation(pt.x, pt.y);
      if ((path == null) || path.equals(_pathSource)) return false;

      return true;
    }
Exemplo n.º 5
0
    public void keyPressed(KeyEvent e) {
      TreePath selectionPath = mainTree.getSelectionPath();
      if (selectionPath == null || mainTree.getSelectionCount() == 0) {
        return;
      }

      if (mainTree.getSelectionCount() == 1) {
        SoapUITreeNode lastPathComponent = (SoapUITreeNode) selectionPath.getLastPathComponent();
        ActionList actions = lastPathComponent.getActions();
        if (actions != null) {
          actions.dispatchKeyEvent(e);
        }

        if (!e.isConsumed()) {
          KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
          if (ks.equals(UISupport.getKeyStroke("alt C"))) {
            mainTree.collapsePath(selectionPath);
            e.consume();
          } else if (ks.equals(UISupport.getKeyStroke("alt E"))) {
            mainTree.collapsePath(selectionPath);
            int row = mainTree.getSelectionRows()[0];
            TreePath nextPath = mainTree.getPathForRow(row + 1);

            TreePath path = mainTree.getPathForRow(row);
            while (path != null && !path.equals(nextPath)) {
              mainTree.expandRow(row);
              path = mainTree.getPathForRow(++row);
            }

            e.consume();
          }
        }
      } else {
        TreePath[] selectionPaths = mainTree.getSelectionPaths();
        List<ModelItem> targets = new ArrayList<ModelItem>();
        for (TreePath treePath : selectionPaths) {
          SoapUITreeNode node = (SoapUITreeNode) treePath.getLastPathComponent();
          targets.add(node.getModelItem());
        }

        if (targets.size() > 0) {
          ActionList actions =
              ActionListBuilder.buildMultiActions(targets.toArray(new ModelItem[targets.size()]));
          if (actions.getActionCount() > 0) {
            actions.dispatchKeyEvent(e);
          }
        }
      }
    }
Exemplo n.º 6
0
  /**
   * Prepares the synchronization process and starts the synchronization.
   *
   * @return true if there were no errors during synchronization process, false otherwise
   * @throws Exception when something happened, synchronize(...) (see above) method deals with
   *     possible problems
   */
  protected Boolean doInBackground() throws Exception {
    showDialog();

    // First goes the JTree main projects root (root node, invisible for users) and then a project
    // root node.
    if (!ProjectServiceUtils.isValidTreePath(treePath) || treePath.getPathCount() < 2) {
      LOG.error("Invalid tree path.");
      syncDialog.appendErrorInfo(INVALID_TREE_PATH_LABEL, true);
      return false;
    }

    final DefaultMutableTreeNode projectRootNode;
    final ProjectRoot projectRoot;
    try {
      projectRootNode = (DefaultMutableTreeNode) treePath.getPathComponent(1);
      projectRoot = (ProjectRoot) projectRootNode.getUserObject();
    } catch (ClassCastException exception) {
      // should never happened, because isValidTreePath() method ensures this; testing & debuging
      // purposes
      LOG.error("Project root not found.");
      syncDialog.appendErrorInfo(PROJECT_ROOT_NOT_FOUND_LABEL, true);
      return false;
    }

    final File projectRootFile =
        new File(
            projectRoot.getProjectLocation(),
            projectRoot.getDisplayName() + ProjectService.PROJECT_FILE_EXTENSION);

    if (projectRootFile.exists()
        && overwriteProjectItems
        &&
        /* overwrite project file only when the project root is set as tree path (constructor argument) */
        treePath.equals(
            ModelerSession.getProjectService().getProjectPath(projectRoot.getDisplayName()))) {

      final SaveProjectResult result =
          ModelerSession.getProjectControlService()
              .saveProject(treePath); // overwrite the project file
      if (!SaveProjectResult.SUCCESS.equals(result)) {
        LOG.error("Not possible to save project file");
        syncDialog.appendErrorInfo(IMPOSSIBLE_TO_SAVE_PROJECT_FILE_LABEL, true);
        return false;
      }

    } else if (!projectRootFile.exists() && addProjectItems) {
      final SaveProjectResult result =
          ModelerSession.getProjectControlService()
              .saveProject(treePath); // create the project file
      if (!SaveProjectResult.SUCCESS.equals(result)) {
        LOG.error("Not possible to save project file");
        syncDialog.appendErrorInfo(IMPOSSIBLE_TO_SAVE_PROJECT_FILE_LABEL, true);
        return false;
      }

    } else if (!projectRootFile.exists()) {
      LOG.error(
          "Project file not found and synchronization is not allowed to add items to the file system.");
      syncDialog.appendErrorInfo(MISSING_PROJECT_FILE_LABEL, true);
      return false;
    }

    final File path =
        syncPathToTreeRootToFS(new File(projectRootFile.getParent()), treePath, addProjectItems);

    if (path == null) {
      syncDialog.appendErrorInfo(SYNC_SUBTREE_BUILD_ERROR_LABEL, true);
      return false;
    }

    /* This is kind of hack to show, that there is no need to continue,
    there are still differences between FS and PN, but the method is not allowed to create FS items. */
    return path.getAbsolutePath().equals("")
        || syncSubtreeToFS(
            path, treePath, addProjectItems, overwriteProjectItems, deleteProjectItems);
  }