1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.uruma.rcp.configuration.extension; |
17 | |
|
18 | |
import org.seasar.framework.util.StringUtil; |
19 | |
import org.seasar.uruma.component.rcp.PerspectiveComponent; |
20 | |
import org.seasar.uruma.component.rcp.WorkbenchComponent; |
21 | |
import org.seasar.uruma.rcp.configuration.Extension; |
22 | |
import org.seasar.uruma.rcp.configuration.ExtensionBuilder; |
23 | |
import org.seasar.uruma.rcp.configuration.ExtensionFactory; |
24 | |
import org.seasar.uruma.rcp.configuration.ExtensionPoints; |
25 | |
import org.seasar.uruma.rcp.configuration.elements.PerspectiveElement; |
26 | |
import org.seasar.uruma.rcp.ui.AutoPerspectiveFactory; |
27 | |
import org.seasar.uruma.rcp.ui.BlankPerspectiveFactory; |
28 | |
import org.seasar.uruma.rcp.ui.GenericPerspectiveFactory; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public class PerspectivesBuilder extends AbstractExtensionBuilder { |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public Extension[] buildExtension() { |
41 | 0 | Extension extension = ExtensionFactory |
42 | |
.createExtension(ExtensionPoints.PERSPECTIVES); |
43 | |
|
44 | 0 | WorkbenchComponent workbenchComponent = service.getWorkbenchComponent(); |
45 | 0 | if (DUMMY_WORKBENCH_PATH.equals(workbenchComponent.getPath())) { |
46 | 0 | return new Extension[] { createBlankPerspective() }; |
47 | |
} |
48 | |
|
49 | 0 | boolean defaultIdUsed = false; |
50 | |
|
51 | |
for (PerspectiveComponent perspective : workbenchComponent |
52 | 0 | .getPerspectives()) { |
53 | |
|
54 | |
|
55 | 0 | if (StringUtil.isBlank(perspective.id) && !defaultIdUsed) { |
56 | 0 | perspective.id = DEFAULT_PERSPECTIVE_ID; |
57 | 0 | defaultIdUsed = true; |
58 | |
} |
59 | |
|
60 | 0 | PerspectiveElement element = new PerspectiveElement(perspective); |
61 | 0 | element.clazz = GenericPerspectiveFactory.class.getName(); |
62 | |
|
63 | 0 | extension.addElement(element); |
64 | 0 | } |
65 | |
|
66 | 0 | if (extension.getElements().size() == 0) { |
67 | |
|
68 | 0 | PerspectiveComponent component = new PerspectiveComponent(); |
69 | 0 | component.clazz = AutoPerspectiveFactory.class.getName(); |
70 | 0 | component.id = DEFAULT_PERSPECTIVE_ID; |
71 | 0 | component.name = service.getPluginId(); |
72 | |
|
73 | 0 | workbenchComponent.addChild(component); |
74 | 0 | workbenchComponent.initialPerspectiveId = DEFAULT_PERSPECTIVE_ID; |
75 | |
|
76 | 0 | PerspectiveElement element = new PerspectiveElement(component); |
77 | 0 | extension.addElement(element); |
78 | |
|
79 | 0 | } else if (StringUtil.isBlank(workbenchComponent.initialPerspectiveId)) { |
80 | |
|
81 | |
|
82 | 0 | PerspectiveComponent perspective = workbenchComponent |
83 | |
.getPerspectives().get(0); |
84 | 0 | workbenchComponent.initialPerspectiveId = perspective.id; |
85 | |
} |
86 | |
|
87 | 0 | return new Extension[] { extension }; |
88 | |
} |
89 | |
|
90 | |
protected Extension createBlankPerspective() { |
91 | 0 | Extension extension = ExtensionFactory |
92 | |
.createExtension(ExtensionPoints.PERSPECTIVES); |
93 | |
|
94 | 0 | PerspectiveElement blank = new PerspectiveElement(); |
95 | 0 | blank.clazz = BlankPerspectiveFactory.class.getName(); |
96 | 0 | blank.id = service.createRcpId(DEFAULT_PERSPECTIVE_ID); |
97 | 0 | blank.name = ""; |
98 | |
|
99 | 0 | extension.addElement(blank); |
100 | 0 | return extension; |
101 | |
} |
102 | |
} |