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          }
76          return this.visible;
77      }
78  
79      @Override
80      public void setVisible(boolean visible) {
81          this.visible = visible;
82      }
83  
84      @Override
85      public boolean isEnabled() {
86          if (!this.enabledLikeChild) {
87                  return true;
88          }
89          IContributionItem[] childItems = getItems();
90  
91          for (int j = 0; j < childItems.length; j++) {
92              if (childItems[j].isVisible() && childItems[j].isEnabled()
93                      && !childItems[j].isSeparator()) {
94                  return true;
95              }
96          }
97  
98          return false;
99      }
100 
101     /***
102      * 
103      * @param node
104      */
105     public void setNode(Node node) {
106         this.node = node;
107     }
108 
109     /***
110      * 
111      * @return node
112      */
113     public Node getNode() {
114         return this.node;
115     }
116 
117     /***
118      * 
119      * @param visibleLikeChild
120      */
121     public void setVisibleLikeChild(boolean visibleLikeChild) {
122         this.visibleLikeChild = visibleLikeChild;
123     }
124 
125     /***
126      * 
127      * @param enabledLikeChild
128      */
129     public void setEnabledLikeChild(boolean enabledLikeChild) {
130         this.enabledLikeChild = enabledLikeChild;
131     }
132 
133 }