1684
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.carbide.internal.discovery.ui.editor;
|
|
18 |
|
1705
|
19 |
import java.util.ArrayList;
|
1734
|
20 |
import java.util.Collections;
|
|
21 |
import java.util.Comparator;
|
1705
|
22 |
import java.util.List;
|
|
23 |
|
|
24 |
import org.eclipse.jface.action.Action;
|
|
25 |
import org.eclipse.jface.action.IAction;
|
|
26 |
import org.eclipse.jface.layout.GridDataFactory;
|
|
27 |
import org.eclipse.jface.layout.GridLayoutFactory;
|
|
28 |
import org.eclipse.jface.resource.ImageDescriptor;
|
|
29 |
import org.eclipse.swt.SWT;
|
|
30 |
import org.eclipse.swt.graphics.Color;
|
|
31 |
import org.eclipse.swt.widgets.Composite;
|
1684
|
32 |
import org.eclipse.swt.widgets.Control;
|
|
33 |
|
1734
|
34 |
import com.nokia.carbide.internal.discovery.ui.editor.PortalEditor.LayerExtension;
|
|
35 |
import com.nokia.carbide.internal.discovery.ui.extension.IActionBar;
|
|
36 |
import com.nokia.carbide.internal.discovery.ui.extension.ICommandBarFactory;
|
1705
|
37 |
import com.nokia.carbide.internal.discovery.ui.extension.IPortalPageLayer;
|
1684
|
38 |
|
|
39 |
|
1705
|
40 |
public class PortalPage implements IActionBar {
|
|
41 |
|
|
42 |
private class ChangeLayerAction extends Action {
|
|
43 |
private Layer layer;
|
|
44 |
|
|
45 |
private ChangeLayerAction(Layer layer) {
|
1721
|
46 |
super(layer.getTitle());
|
1705
|
47 |
this.layer = layer;
|
|
48 |
}
|
|
49 |
|
|
50 |
public void run() {
|
|
51 |
setCurrentLayer(layer);
|
|
52 |
}
|
|
53 |
|
|
54 |
public boolean isEnabled() {
|
|
55 |
return !layer.equals(currentLayer);
|
|
56 |
}
|
|
57 |
}
|
1684
|
58 |
|
1705
|
59 |
private class Layer {
|
|
60 |
private IPortalPageLayer layer;
|
|
61 |
private boolean initialized;
|
|
62 |
private Control control;
|
1721
|
63 |
private String title;
|
1705
|
64 |
|
1721
|
65 |
public Layer(IPortalPageLayer layer, String title) {
|
1705
|
66 |
this.layer = layer;
|
1721
|
67 |
this.title = title;
|
1705
|
68 |
}
|
|
69 |
|
|
70 |
public IPortalPageLayer getLayer() {
|
|
71 |
return layer;
|
|
72 |
}
|
|
73 |
|
|
74 |
public void initialize() {
|
|
75 |
layer.init();
|
|
76 |
this.initialized = true;
|
|
77 |
}
|
|
78 |
|
|
79 |
public boolean isInitialized() {
|
|
80 |
return initialized;
|
|
81 |
}
|
|
82 |
|
|
83 |
public void setControl(Control control) {
|
|
84 |
this.control = control;
|
|
85 |
}
|
|
86 |
|
|
87 |
public Control getControl() {
|
|
88 |
return control;
|
|
89 |
}
|
1721
|
90 |
|
|
91 |
public String getTitle() {
|
|
92 |
return title;
|
|
93 |
}
|
1684
|
94 |
}
|
|
95 |
|
1705
|
96 |
private String title;
|
2062
|
97 |
private String tooltip;
|
1705
|
98 |
private ImageDescriptor imageDescriptor;
|
1734
|
99 |
private String id;
|
|
100 |
private final ICommandBarFactory commandBarFactory;
|
1705
|
101 |
private StackComposite pageComposite;
|
|
102 |
private boolean initialized;
|
|
103 |
private List<Layer> layers;
|
|
104 |
private Layer currentLayer;
|
|
105 |
private IAction[] actions;
|
1734
|
106 |
private List<TaskBar> pageTaskBars;
|
1684
|
107 |
|
2062
|
108 |
public PortalPage(String title, String tooltip, ImageDescriptor imageDescriptor, String id,
|
1734
|
109 |
List<LayerExtension> layerExtensions, ICommandBarFactory commandBarFactory) {
|
1705
|
110 |
this.title = title;
|
2062
|
111 |
this.tooltip = tooltip;
|
1705
|
112 |
this.imageDescriptor = imageDescriptor;
|
|
113 |
this.id = id;
|
1734
|
114 |
this.commandBarFactory = commandBarFactory;
|
|
115 |
layers = new ArrayList<Layer>(layerExtensions.size());
|
|
116 |
Collections.sort(layerExtensions, new Comparator<LayerExtension>() {
|
|
117 |
@Override
|
|
118 |
public int compare(LayerExtension o1, LayerExtension o2) {
|
|
119 |
return o1.order - o2.order;
|
|
120 |
}
|
|
121 |
});
|
|
122 |
for (LayerExtension layerExtension : layerExtensions) {
|
|
123 |
layers.add(new Layer(layerExtension.layer, layerExtension.title));
|
1705
|
124 |
}
|
1734
|
125 |
pageTaskBars = new ArrayList<TaskBar>(layerExtensions.size());
|
1684
|
126 |
}
|
|
127 |
|
1705
|
128 |
public String getId() {
|
|
129 |
return id;
|
|
130 |
}
|
|
131 |
|
|
132 |
public String getTitle() {
|
|
133 |
return title;
|
1684
|
134 |
}
|
|
135 |
|
2062
|
136 |
public String getTooltip() {
|
|
137 |
return tooltip;
|
|
138 |
}
|
|
139 |
|
1705
|
140 |
public ImageDescriptor getImageDescriptor() {
|
|
141 |
return imageDescriptor;
|
|
142 |
}
|
|
143 |
|
|
144 |
public Control getPageControl() {
|
|
145 |
return pageComposite;
|
1684
|
146 |
}
|
|
147 |
|
1705
|
148 |
public void initialize() {
|
|
149 |
setCurrentLayer(layers.get(0));
|
|
150 |
initialized = true;
|
1684
|
151 |
}
|
|
152 |
|
|
153 |
public boolean isInitialized() {
|
|
154 |
return initialized;
|
|
155 |
}
|
1705
|
156 |
|
|
157 |
public void createPageComposite(Composite parent, PortalEditor portalEditor) {
|
|
158 |
Composite backgroundParent = portalEditor.getBackgroundParent();
|
|
159 |
pageComposite = new StackComposite(parent, backgroundParent);
|
|
160 |
for (Layer layer : layers) {
|
|
161 |
Composite layerComposite = new SharedBackgroundComposite(pageComposite, backgroundParent);
|
|
162 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(layerComposite);
|
2035
|
163 |
GridLayoutFactory.fillDefaults().numColumns(2).spacing(10, 0).extendedMargins(0, 0, 10, 0).applyTo(layerComposite);
|
1705
|
164 |
createTaskBarControls(portalEditor, layerComposite, layer.getLayer());
|
|
165 |
createMainControl(portalEditor, layerComposite, layer.getLayer());
|
|
166 |
layer.setControl(layerComposite);
|
|
167 |
}
|
|
168 |
}
|
1684
|
169 |
|
1705
|
170 |
protected void createTaskBarControls(PortalEditor portalEditor, Composite pageComposite, IPortalPageLayer layerExtension) {
|
|
171 |
Composite backgroundParent = portalEditor.getBackgroundParent();
|
|
172 |
Composite taskComposite = new SharedBackgroundComposite(pageComposite, backgroundParent);
|
|
173 |
GridLayoutFactory.fillDefaults().applyTo(taskComposite);
|
|
174 |
GridDataFactory.fillDefaults().grab(false, true).applyTo(taskComposite);
|
|
175 |
TaskBar taskBar = new TaskBar(taskComposite, backgroundParent, this);
|
2035
|
176 |
GridDataFactory.fillDefaults().minSize(120, SWT.DEFAULT).grab(true, false).indent(0, 0).applyTo(taskBar);
|
1734
|
177 |
pageTaskBars.add(taskBar);
|
1705
|
178 |
ActionUIUpdater updater = new ActionUIUpdater();
|
1734
|
179 |
createCommandBars(backgroundParent, taskComposite, updater,
|
|
180 |
layerExtension.createCommandBars(portalEditor, updater));
|
|
181 |
if (commandBarFactory != null) {
|
|
182 |
createCommandBars(backgroundParent, taskComposite, updater,
|
|
183 |
commandBarFactory.createCommandBars(portalEditor, updater));
|
|
184 |
|
|
185 |
}
|
|
186 |
}
|
|
187 |
|
|
188 |
private void createCommandBars(Composite backgroundParent, Composite taskComposite,
|
|
189 |
ActionUIUpdater updater, IActionBar[] commandBars) {
|
1721
|
190 |
if (commandBars != null) {
|
|
191 |
for (IActionBar actionBar : commandBars) {
|
1734
|
192 |
TaskBar taskBar = new TaskBar(taskComposite, backgroundParent, actionBar);
|
1721
|
193 |
updater.addTaskBar(taskBar);
|
|
194 |
GridDataFactory.fillDefaults().minSize(150, SWT.DEFAULT).grab(true, false).indent(0, 0).applyTo(taskBar);
|
|
195 |
}
|
1705
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
protected void createMainControl(PortalEditor portalEditor, Composite pageComposite, IPortalPageLayer layerExtension) {
|
|
200 |
Color background = pageComposite.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
|
|
201 |
Composite mainControl =
|
|
202 |
new RoundedCornerComposite(pageComposite, portalEditor.getBackgroundParent(), null, background);
|
|
203 |
GridLayoutFactory.fillDefaults().margins(2, 2).applyTo(mainControl);
|
|
204 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(mainControl);
|
|
205 |
Control control = layerExtension.createControl(mainControl, portalEditor);
|
|
206 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(control);
|
|
207 |
}
|
|
208 |
|
|
209 |
@Override
|
|
210 |
public IAction[] getActions() {
|
|
211 |
if (actions == null) {
|
|
212 |
actions = new Action[layers.size()];
|
|
213 |
int i = 0;
|
|
214 |
for (Layer layer : layers) {
|
|
215 |
actions[i++] = new ChangeLayerAction(layer);
|
|
216 |
}
|
|
217 |
}
|
|
218 |
return actions;
|
|
219 |
}
|
|
220 |
|
|
221 |
@Override
|
|
222 |
public String[] getHighlightedActionIds() {
|
|
223 |
return null;
|
|
224 |
}
|
|
225 |
|
|
226 |
protected void setCurrentLayer(Layer layer) {
|
|
227 |
currentLayer = layer;
|
|
228 |
pageComposite.showControl(currentLayer.getControl());
|
|
229 |
if (!currentLayer.isInitialized())
|
|
230 |
currentLayer.initialize();
|
1734
|
231 |
for (TaskBar taskBar : pageTaskBars) {
|
1705
|
232 |
taskBar.updateAllActionsUI();
|
|
233 |
}
|
|
234 |
}
|
1684
|
235 |
}
|