Skip to main content
summaryrefslogtreecommitdiffstats
blob: 210e052ed8af84158b0eacbf71ec185dea921db4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.ws.internal.explorer.platform.actions;

import javax.servlet.http.HttpServletRequest;
import org.eclipse.wst.ws.internal.explorer.platform.constants.ActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Controller;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Node;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.NodeManager;

public abstract class NodeAction extends LinkAction
{
  protected NodeManager nodeManager_;
  private boolean requiresTreeViewRefresh_;
  private boolean requiresNodeSelection_;
  private boolean requiresViewSelection_;
  private boolean requiresStatusUpdate_;

  public NodeAction(Controller controller,NodeManager nodeManager)
  {
    super(controller);
    nodeManager_ = nodeManager;
    requiresTreeViewRefresh_ = false;
    requiresNodeSelection_ = false;
    requiresViewSelection_ = false;
    requiresStatusUpdate_ = false;
  }

  // ...jsp?nodeId=...<&isHistory=1>
  protected boolean processLinkParameters(HttpServletRequest request)
  {
    String nodeIdString = request.getParameter(ActionInputs.NODEID);
    // Perform data validation.
    try
    {
      Integer.parseInt(nodeIdString);
    }
    catch (NumberFormatException e)
    {
      // Validation failed!
      return false;
    }
    propertyTable_.put(ActionInputs.NODEID,nodeIdString);
    return true;
  }

  protected final boolean isStaleNode(int nodeId)
  {
    return (nodeManager_.getNode(nodeId) == null);
  }

  /**
  * Make a node visible. A node is visible when all of its ancestors are expanded.
  * @param Node The node to be made visible.
  * @return boolean Indicator for whether or not the tree structure was changed (i.e. expanded to show the node in question).
  */
  protected final boolean makeNodeVisible(Node node)
  {
    requiresTreeViewRefresh_ = node.getNodeManager().makeNodeVisible(node);
    return requiresTreeViewRefresh_;
  }

  /**
  * Select a node with id nodeId.
  * @param int The id of the node to be selected.
  */
  protected final void setSelectedNodeId(int nodeId)
  {
    if (nodeManager_.getSelectedNodeId() != nodeId)
    {
      requiresNodeSelection_ = true;
      nodeManager_.setSelectedNodeId(nodeId);
    }
  }

  protected final void setSelectedViewId(int viewId)
  {
    Node selectedNode = nodeManager_.getSelectedNode();
    if (selectedNode.getViewId() != viewId)
    {
      requiresViewSelection_ = true;
      selectedNode.setViewId(viewId);
    }
  }

  // Determine whether or not the treeview requires reloading as a result of this action.
  // Reloading is required when branches are added/removed.
  public boolean requiresTreeViewRefresh()
  {
    return requiresTreeViewRefresh_;
  }

  // Determine whether or not a new node has been selected as a result of the action.
  public boolean requiresNodeSelection()
  {
    return requiresNodeSelection_;
  }

  // Determine if a new view element is selected.
  public boolean requiresViewSelection()
  {
    return requiresViewSelection_;
  }

  // Determine if any status messages arose from this action.
  public boolean requiresStatusUpdate()
  {
    return requiresStatusUpdate_;
  }

  protected abstract String getActionLinkForHistory();
}

Back to the top