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;
|
|
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import org.eclipse.jface.action.Action;
|
|
23 |
import org.eclipse.jface.action.IAction;
|
|
24 |
import org.eclipse.jface.layout.GridDataFactory;
|
|
25 |
import org.eclipse.jface.layout.GridLayoutFactory;
|
|
26 |
import org.eclipse.jface.resource.ImageDescriptor;
|
|
27 |
import org.eclipse.swt.SWT;
|
|
28 |
import org.eclipse.swt.graphics.Color;
|
|
29 |
import org.eclipse.swt.widgets.Composite;
|
1684
|
30 |
import org.eclipse.swt.widgets.Control;
|
|
31 |
|
1705
|
32 |
import com.nokia.carbide.internal.discovery.ui.extension.IPortalPageLayer;
|
|
33 |
import com.nokia.carbide.internal.discovery.ui.extension.IPortalPageLayer.IActionBar;
|
1684
|
34 |
|
|
35 |
|
1705
|
36 |
public class PortalPage implements IActionBar {
|
|
37 |
|
|
38 |
private class ChangeLayerAction extends Action {
|
|
39 |
private Layer layer;
|
|
40 |
|
|
41 |
private ChangeLayerAction(Layer layer) {
|
|
42 |
super(layer.getLayer().getTitle());
|
|
43 |
this.layer = layer;
|
|
44 |
}
|
|
45 |
|
|
46 |
public void run() {
|
|
47 |
setCurrentLayer(layer);
|
|
48 |
}
|
|
49 |
|
|
50 |
public boolean isEnabled() {
|
|
51 |
return !layer.equals(currentLayer);
|
|
52 |
}
|
|
53 |
}
|
1684
|
54 |
|
1705
|
55 |
private class Layer {
|
|
56 |
private IPortalPageLayer layer;
|
|
57 |
private boolean initialized;
|
|
58 |
private Control control;
|
|
59 |
|
|
60 |
public Layer(IPortalPageLayer layer) {
|
|
61 |
this.layer = layer;
|
|
62 |
}
|
|
63 |
|
|
64 |
public IPortalPageLayer getLayer() {
|
|
65 |
return layer;
|
|
66 |
}
|
|
67 |
|
|
68 |
public void initialize() {
|
|
69 |
layer.init();
|
|
70 |
this.initialized = true;
|
|
71 |
}
|
|
72 |
|
|
73 |
public boolean isInitialized() {
|
|
74 |
return initialized;
|
|
75 |
}
|
|
76 |
|
|
77 |
public void setControl(Control control) {
|
|
78 |
this.control = control;
|
|
79 |
}
|
|
80 |
|
|
81 |
public Control getControl() {
|
|
82 |
return control;
|
|
83 |
}
|
1684
|
84 |
}
|
|
85 |
|
1705
|
86 |
private String id;
|
|
87 |
private String title;
|
|
88 |
private ImageDescriptor imageDescriptor;
|
|
89 |
private StackComposite pageComposite;
|
|
90 |
private boolean initialized;
|
|
91 |
private List<Layer> layers;
|
|
92 |
private Layer currentLayer;
|
|
93 |
private IAction[] actions;
|
|
94 |
private List<TaskBar> navigationTaskBars;
|
1684
|
95 |
|
1705
|
96 |
public PortalPage(String title, ImageDescriptor imageDescriptor, String id, List<IPortalPageLayer> layerExtensions) {
|
|
97 |
this.title = title;
|
|
98 |
this.imageDescriptor = imageDescriptor;
|
|
99 |
this.id = id;
|
|
100 |
layers = new ArrayList<Layer>(layerExtensions.size());
|
|
101 |
for (IPortalPageLayer layerExtension : layerExtensions) {
|
|
102 |
layers.add(new Layer(layerExtension));
|
|
103 |
}
|
|
104 |
navigationTaskBars = new ArrayList<TaskBar>(layerExtensions.size());
|
1684
|
105 |
}
|
|
106 |
|
1705
|
107 |
public String getId() {
|
|
108 |
return id;
|
|
109 |
}
|
|
110 |
|
|
111 |
public String getTitle() {
|
|
112 |
return title;
|
1684
|
113 |
}
|
|
114 |
|
1705
|
115 |
public ImageDescriptor getImageDescriptor() {
|
|
116 |
return imageDescriptor;
|
|
117 |
}
|
|
118 |
|
|
119 |
public Control getPageControl() {
|
|
120 |
return pageComposite;
|
1684
|
121 |
}
|
|
122 |
|
1705
|
123 |
public void initialize() {
|
|
124 |
setCurrentLayer(layers.get(0));
|
|
125 |
initialized = true;
|
1684
|
126 |
}
|
|
127 |
|
|
128 |
public boolean isInitialized() {
|
|
129 |
return initialized;
|
|
130 |
}
|
1705
|
131 |
|
|
132 |
public void createPageComposite(Composite parent, PortalEditor portalEditor) {
|
|
133 |
Composite backgroundParent = portalEditor.getBackgroundParent();
|
|
134 |
pageComposite = new StackComposite(parent, backgroundParent);
|
|
135 |
for (Layer layer : layers) {
|
|
136 |
Composite layerComposite = new SharedBackgroundComposite(pageComposite, backgroundParent);
|
|
137 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(layerComposite);
|
|
138 |
GridLayoutFactory.fillDefaults().numColumns(2).spacing(20, 0).extendedMargins(20, 20, 20, 0).applyTo(layerComposite);
|
|
139 |
createTaskBarControls(portalEditor, layerComposite, layer.getLayer());
|
|
140 |
createMainControl(portalEditor, layerComposite, layer.getLayer());
|
|
141 |
layer.setControl(layerComposite);
|
|
142 |
}
|
|
143 |
}
|
1684
|
144 |
|
1705
|
145 |
protected void createTaskBarControls(PortalEditor portalEditor, Composite pageComposite, IPortalPageLayer layerExtension) {
|
|
146 |
Composite backgroundParent = portalEditor.getBackgroundParent();
|
|
147 |
Composite taskComposite = new SharedBackgroundComposite(pageComposite, backgroundParent);
|
|
148 |
GridLayoutFactory.fillDefaults().applyTo(taskComposite);
|
|
149 |
GridDataFactory.fillDefaults().grab(false, true).applyTo(taskComposite);
|
|
150 |
TaskBar taskBar = new TaskBar(taskComposite, backgroundParent, this);
|
|
151 |
GridDataFactory.fillDefaults().minSize(150, SWT.DEFAULT).grab(true, false).indent(0, 0).applyTo(taskBar);
|
|
152 |
navigationTaskBars.add(taskBar);
|
|
153 |
ActionUIUpdater updater = new ActionUIUpdater();
|
|
154 |
IActionBar[] commandBars = layerExtension.createCommandBars(portalEditor, updater);
|
|
155 |
for (IActionBar actionBar : commandBars) {
|
|
156 |
taskBar = new TaskBar(taskComposite, backgroundParent, actionBar);
|
|
157 |
updater.addTaskBar(taskBar);
|
|
158 |
GridDataFactory.fillDefaults().minSize(150, SWT.DEFAULT).grab(true, false).indent(0, 0).applyTo(taskBar);
|
|
159 |
}
|
|
160 |
}
|
|
161 |
|
|
162 |
protected void createMainControl(PortalEditor portalEditor, Composite pageComposite, IPortalPageLayer layerExtension) {
|
|
163 |
Color background = pageComposite.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
|
|
164 |
Composite mainControl =
|
|
165 |
new RoundedCornerComposite(pageComposite, portalEditor.getBackgroundParent(), null, background);
|
|
166 |
GridLayoutFactory.fillDefaults().margins(2, 2).applyTo(mainControl);
|
|
167 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(mainControl);
|
|
168 |
Control control = layerExtension.createControl(mainControl, portalEditor);
|
|
169 |
GridDataFactory.fillDefaults().grab(true, true).applyTo(control);
|
|
170 |
}
|
|
171 |
|
|
172 |
@Override
|
|
173 |
public IAction[] getActions() {
|
|
174 |
if (actions == null) {
|
|
175 |
actions = new Action[layers.size()];
|
|
176 |
int i = 0;
|
|
177 |
for (Layer layer : layers) {
|
|
178 |
actions[i++] = new ChangeLayerAction(layer);
|
|
179 |
}
|
|
180 |
}
|
|
181 |
return actions;
|
|
182 |
}
|
|
183 |
|
|
184 |
@Override
|
|
185 |
public String[] getHighlightedActionIds() {
|
|
186 |
return null;
|
|
187 |
}
|
|
188 |
|
|
189 |
protected void setCurrentLayer(Layer layer) {
|
|
190 |
currentLayer = layer;
|
|
191 |
pageComposite.showControl(currentLayer.getControl());
|
|
192 |
if (!currentLayer.isInitialized())
|
|
193 |
currentLayer.initialize();
|
|
194 |
for (TaskBar taskBar : navigationTaskBars) {
|
|
195 |
taskBar.updateAllActionsUI();
|
|
196 |
}
|
|
197 |
}
|
1684
|
198 |
}
|