1 /*
2 * Copyright 2004-2008 the Seasar Foundation and the Others.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
15 */
16 package org.seasar.uruma.component.base;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.seasar.uruma.component.UIElement;
22 import org.seasar.uruma.component.UIHasMenuCompositeComponent;
23 import org.seasar.uruma.component.jface.CompositeComponent;
24 import org.seasar.uruma.component.jface.MenuComponent;
25
26 /**
27 * {@link AbstractUIHasMenuCompositeComponent} を表す基底クラスです。<br />
28 * RCPに定義するメニューを利用するクラスの基底クラスとして使用します。<br />
29 *
30 * @author y.sugigami
31 */
32 public abstract class AbstractUIHasMenuCompositeComponent extends
33 CompositeComponent implements UIHasMenuCompositeComponent {
34 /*
35 * @see org.seasar.uruma.component.UIHasMenuCompositeComponent#getMenus()
36 */
37 public List<MenuComponent> getMenus() {
38 return getElements(MenuComponent.class);
39 }
40
41 protected <E> List<E> getElements(final Class<E> clazz) {
42 List<E> result = new ArrayList<E>(getChildren().size());
43 for (UIElement element : getChildren()) {
44 if (clazz.isAssignableFrom(element.getClass())) {
45 result.add(clazz.cast(element));
46 }
47 }
48 return result;
49 }
50 }