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.rcp;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.eclipse.swt.SWT;
22 import org.seasar.uruma.component.UIElement;
23 import org.seasar.uruma.component.base.AbstractUIContainer;
24 import org.seasar.uruma.component.jface.MenuComponent;
25
26 /**
27 * ワークベンチのためのコンポーネントです。<br />
28 *
29 * @author y-komori
30 */
31 public class WorkbenchComponent extends AbstractUIContainer {
32 /**
33 * ID です。<br />
34 */
35 public String id;
36
37 /**
38 * ワークベンチウィンドウのタイトルです。
39 */
40 public String title;
41
42 /**
43 * ワークベンチウィンドウに表示するアイコンのイメージパスです。
44 */
45 public String image;
46
47 /**
48 * ワークベンチウィンドウのスタイルです。
49 *
50 * @see SWT
51 */
52 public String style;
53
54 /**
55 * ワークベンチウィンドウの初期ウィンドウ幅です。
56 */
57 public String initWidth;
58
59 /**
60 * ワークベンチウィンドウの初期ウィンドウ高さです。
61 */
62 public String initHeight;
63
64 /**
65 * ワークベンチのメニューバーに表示する <code>menu</code> 要素の ID です。
66 */
67 public String menu;
68
69 /**
70 * ステータスラインの表示/非表示を指定します。
71 */
72 public String statusLine;
73
74 /**
75 * 最初に表示するパースペクティブの ID です。
76 */
77 public String initialPerspectiveId;
78
79 /**
80 * ウィンドウの位置・サイズの保存可否を指定します。
81 */
82 public String saveAndRestore;
83
84 /**
85 * ウィンドウの位置・サイズの保存可否を指定します。
86 */
87 public String menuBar;
88
89 /**
90 * クールバーの表示/非表示を指定します。
91 */
92 public String coolBar;
93
94 /**
95 * ファーストビューバーの表示/非表示を指定します。
96 */
97 public String fastViewBars;
98
99 /**
100 * パースぺクティブバーの表示/非表示を指定します。
101 */
102 public String perspectiveBar;
103
104 /**
105 * プログレスバーの表示/非表示を指定します。
106 */
107 public String progressIndicator;
108
109 /**
110 * 指定された ID を持つ {@link PerspectiveComponent} を検索して返します。<br />
111 *
112 * @param rowId
113 * ID (画面定義 XML 上の ID)
114 * @return {@link PerspectiveComponent} オブジェクト
115 */
116 public PerspectiveComponent findPerspective(final String rowId) {
117 if (rowId == null) {
118 return null;
119 }
120
121 for (UIElement element : children) {
122 if (element instanceof PerspectiveComponent) {
123 if (rowId.equals(((PerspectiveComponent) element).id)) {
124 return (PerspectiveComponent) element;
125 }
126 }
127 }
128
129 return null;
130 }
131
132 /**
133 * {@link WorkbenchComponent} が保持する {@link PerspectiveComponent} のリストを返します。<br />
134 *
135 * @return {@link PerspectiveComponent} のリスト
136 */
137 public List<PerspectiveComponent> getPerspectives() {
138 return getElements(PerspectiveComponent.class);
139 }
140
141 /**
142 * {@link WorkbenchComponent} が保持する {@link MenuComponent} のリストを返します。<br />
143 *
144 * @return {@link MenuComponent} のリスト
145 */
146 public List<MenuComponent> getMenus() {
147 return getElements(MenuComponent.class);
148 }
149
150 protected <E> List<E> getElements(final Class<E> clazz) {
151 List<E> result = new ArrayList<E>(children.size());
152
153 for (UIElement element : children) {
154 if (clazz.isAssignableFrom(element.getClass())) {
155 result.add(clazz.cast(element));
156 }
157 }
158
159 return result;
160 }
161 }