View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics and Informatics, Comenius
3    * University, Bratislava. This file is protected by the Mozilla Public License
4    * version 1.1 (the License); you may not use this file except in compliance
5    * with the License. You may obtain a copy of the License at
6    * http://euromath2.sourceforge.net/license.html Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is
8    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9    * KIND, either express or implied. See the License for the specific language
10   * governing permissions and limitations under the License.
11   */
12  package sk.uniba.euromath.editor.xmlEditor.actions;
13  
14  import org.eclipse.jface.action.IContributionItem;
15  import org.eclipse.jface.action.MenuManager;
16  import org.w3c.dom.Node;
17  
18  /***
19   * @author Tomáš Studva 6.7.2005
20   */
21  public class EMMenuManager extends MenuManager {
22  
23      /***
24       * Manages visibility by user.
25       */
26      protected boolean visible = true;
27  
28      /***
29       * If true, then is visible only if have visible child.
30       */
31      protected boolean visibleLikeChild = false;
32  
33      /***
34       * If true, then is enabled only if have enabled visible not separator
35       * child.
36       */
37      protected boolean enabledLikeChild = false;
38  
39      /***
40       * Node associated with manager(menu/submenu).
41       */
42      protected Node node;
43  
44      /***
45       * Contructor.
46       * 
47       */
48      public EMMenuManager() {
49          super();
50      }
51  
52      /***
53       * Contructor.
54       * 
55       * @param text
56       */
57      public EMMenuManager(String text) {
58          super(text, null);
59      }
60  
61      /***
62       * Contructor.
63       * 
64       * @param text
65       * @param id
66       */
67      public EMMenuManager(String text, String id) {
68          super(text, id);
69      }
70  
71      @Override
72      public boolean isVisible() {
73          if (this.visibleLikeChild)
74              return super.isVisible();
75          return this.visible;
76      }
77  
78      @Override
79      public void setVisible(boolean visible) {
80          this.visible = visible;
81      }
82  
83      @Override
84      public boolean isEnabled() {
85          if (!this.enabledLikeChild)
86              return true;
87          IContributionItem[] childItems = getItems();
88  
89          for (int j = 0; j < childItems.length; j++) {
90              if (childItems[j].isVisible() && childItems[j].isEnabled()
91                      && !childItems[j].isSeparator()) {
92                  return true;
93              }
94          }
95  
96          return false;
97      }
98  
99      /***
100      * 
101      * @param node
102      */
103     public void setNode(Node node) {
104         this.node = node;
105     }
106 
107     /***
108      * 
109      * @return node
110      */
111     public Node getNode() {
112         return this.node;
113     }
114 
115     /***
116      * 
117      * @param visibleLikeChild
118      */
119     public void setVisibleLikeChild(boolean visibleLikeChild) {
120         this.visibleLikeChild = visibleLikeChild;
121     }
122 
123     /***
124      * 
125      * @param enabledLikeChild
126      */
127     public void setEnabledLikeChild(boolean enabledLikeChild) {
128         this.enabledLikeChild = enabledLikeChild;
129     }
130 
131 }