Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6275daf4f150fb9a39bd4dfbc7e37b93f135977f (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*******************************************************************************
 * 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.wsdl.ui.internal.graph;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.wst.wsdl.ui.internal.WSDLEditorPlugin;

public class ViewMode 
{
  public static final int BINDING     =   1;
  public static final int MESSAGE     =   2;
  public static final int PORT_TYPE   =   3;
  public static final int SERVICE     =   4;
  public static final int TYPES       =   5;

  public static final String BINDING_DESCRIPTION     = WSDLEditorPlugin.getWSDLString("_UI_LABEL_BINDING");
  public static final String MESSAGE_DESCRIPTION     = WSDLEditorPlugin.getWSDLString("_UI_LABEL_MESSAGE");
  public static final String PORT_TYPE_DESCRIPTION   = WSDLEditorPlugin.getWSDLString("_UI_LABEL_PORTTYPE");
  public static final String SERVICE_DESCRIPTION     = WSDLEditorPlugin.getWSDLString("_UI_LABEL_SERVICE");
  public static final String TYPES_DESCRIPTION       = WSDLEditorPlugin.getWSDLString("_UI_LABEL_TYPES");


  protected boolean isBindingVisible = true;
  protected int mode = SERVICE;
  protected List listenerList = new ArrayList();

  public ViewMode()
  {
  }                              

  public void setBindingVisible(boolean isVisible)
  {
    if (isBindingVisible != isVisible)
    {
      isBindingVisible = isVisible;
      fireChangeNotification();
    }
  }

  public boolean isBindingVisible()
  {                                                   
    return isBindingVisible;
  }

  public static int getModeForDescription(String description)
  {               
    int result = SERVICE;
    if (description.equals(BINDING_DESCRIPTION))
    {               
      result = BINDING; 
    }
    else if (description.equals(MESSAGE_DESCRIPTION))
    {        
      result = MESSAGE;
    }
    else if (description.equals(PORT_TYPE_DESCRIPTION))
    { 
      result = PORT_TYPE;
    }
    else if (description.equals(SERVICE_DESCRIPTION))
    {    
      result = SERVICE;
    }
    else if (description.equals(TYPES_DESCRIPTION))
    {  
      result = TYPES;
    }    
    return result;
  }

  public static String getDescriptionForMode(int mode)
  {               
    String result = SERVICE_DESCRIPTION;
    switch (mode)
    {
      case BINDING :
      {             
        result = BINDING_DESCRIPTION;
        break;
      }
      case MESSAGE : 
      {             
        result = MESSAGE_DESCRIPTION;
        break;
      }
      case PORT_TYPE : 
      {             
        result = PORT_TYPE_DESCRIPTION;
        break;
      }
      case SERVICE : 
      {             
        result = SERVICE_DESCRIPTION;
        break;
      }
      case TYPES :  
      {             
        result = TYPES_DESCRIPTION;
        break;
      }
    }
    return result;
  }

  public interface Listener
  {
    public void viewModeChanged(ViewMode mode);
  }

  public void setMode(int mode)
  {
    this.mode = mode;
    fireChangeNotification();
  }

  public void setMode(String description)
  {
    this.mode = getModeForDescription(description);
    fireChangeNotification();
  }

  public int getMode()
  {
    return mode;
  } 

  public String getModeDescription()
  {
    return getDescriptionForMode(mode);
  }

  public void addListener(Listener listener)
  {
    if (!listenerList.contains(listener))
    { 
      listenerList.add(listener);
    }  
  }

  public void removeListener(Listener listener)
  {
    listenerList.remove(listener);
  }  

  public void fireChangeNotification()
  {
    for (Iterator i = listenerList.iterator(); i.hasNext(); )
    {
      Listener listener = (Listener)i.next();
      listener.viewModeChanged(this);
    }
  }
}

Back to the top