Skip to main content
summaryrefslogtreecommitdiffstats
blob: a48b2952b038a87c96afefca3863d55007901ef3 (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
/*******************************************************************************
 * Copyright (c) 2004, 2005 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.wsil.actions;

import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.wst.ws.internal.explorer.platform.constants.ActionInputs;
import org.eclipse.wst.ws.internal.explorer.platform.datamodel.TreeElement;
import org.eclipse.wst.ws.internal.explorer.platform.favorites.datamodel.FavoritesFolderElement;
import org.eclipse.wst.ws.internal.explorer.platform.favorites.perspective.FavoritesPerspective;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Controller;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.NodeManager;
import org.eclipse.wst.ws.internal.explorer.platform.perspective.Tool;
import org.eclipse.wst.ws.internal.explorer.platform.wsil.perspective.ListUDDIBusinessTool;
import org.eclipse.wst.ws.internal.explorer.platform.wsil.perspective.ListUDDIServicesTool;
import org.eclipse.wst.ws.internal.explorer.platform.wsil.perspective.ListWSDLServicesTool;

public abstract class AddToFavoritesAction extends MultipleLinkAction {
    protected NodeManager nodeManager_;

    public AddToFavoritesAction(Controller controller)
    {
        super(controller);
        nodeManager_ = controller.getWSILPerspective().getNodeManager();
    }

    public static String getActionLink(int nodeID, int toolID, int viewID, int viewToolID)
    {
        StringBuffer actionLink = new StringBuffer("wsil/actions/WsilCheckFavoriteExistsActionJSP.jsp?");
        actionLink.append(ActionInputs.NODEID);
        actionLink.append('=');
        actionLink.append(nodeID);
        actionLink.append('&');
        actionLink.append(ActionInputs.TOOLID);
        actionLink.append('=');
        actionLink.append(toolID);
        actionLink.append('&');
        actionLink.append(ActionInputs.VIEWID);
        actionLink.append('=');
        actionLink.append(viewID);
        actionLink.append('&');
        actionLink.append(ActionInputs.VIEWTOOLID);
        actionLink.append('=');
        actionLink.append(viewToolID);
        return actionLink.toString();
    }

    public static String getBaseActionLink() {
        return "wsil/actions/WsilCheckFavoriteExistsActionJSP.jsp";
    }

    public static AddToFavoritesAction newAction(HttpServletRequest request, Controller controller) {
      String nodeID = request.getParameter(ActionInputs.NODEID);
      NodeManager nodeManager = controller.getWSILPerspective().getNodeManager();
      Tool selectedTool = nodeManager.getNode(Integer.parseInt(nodeID)).getToolManager().getSelectedTool();
      if (selectedTool instanceof ListWSDLServicesTool)
        return new AddWSDLServiceToFavoritesAction(controller);
      else if (selectedTool instanceof ListUDDIServicesTool)
        return new AddServiceToFavoritesAction(controller);
      else if (selectedTool instanceof ListUDDIBusinessTool)
        return new AddBusinessToFavoritesAction(controller);
      else
        return new AddWSILToFavoritesAction(controller);
    }

    protected boolean addToFavorites(Hashtable table, String rel) {
        FavoritesPerspective favPerspective = controller_.getFavoritesPerspective();
        NodeManager favNodeManager = favPerspective.getNodeManager();
        TreeElement favRootElement = favNodeManager.getRootNode().getTreeElement();
        Enumeration e = favRootElement.getElements(rel);
        if (!e.hasMoreElements()) return false;
        FavoritesFolderElement favFolderElement = (FavoritesFolderElement)e.nextElement();
        return favFolderElement.addFavorite(table);
    }

    protected boolean favoriteExists(Hashtable table, String rel) {
        FavoritesPerspective favPerspective = controller_.getFavoritesPerspective();
        NodeManager favNodeManager = favPerspective.getNodeManager();
        TreeElement favRootElement = favNodeManager.getRootNode().getTreeElement();
        Enumeration e = favRootElement.getElements(rel);
        if (!e.hasMoreElements()) return false;
        FavoritesFolderElement favFolderElement = (FavoritesFolderElement)e.nextElement();
        return favFolderElement.favoriteExists(table);
    }

    public abstract boolean favoriteExists();
}

Back to the top