Skip to content

Package: EditorToolBar

EditorToolBar

nameinstructionbranchcomplexitylinemethod
EditorToolBar(Composite, int, String, List)
M: 0 C: 201
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 40
100%
M: 0 C: 1
100%
dispose()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Clemens Elflein - initial implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.editor.ui;
15:
16: import java.util.List;
17:
18: import org.eclipse.emfforms.internal.editor.Activator;
19: import org.eclipse.jface.action.Action;
20: import org.eclipse.jface.action.ToolBarManager;
21: import org.eclipse.jface.resource.FontDescriptor;
22: import org.eclipse.jface.resource.ImageDescriptor;
23: import org.eclipse.swt.SWT;
24: import org.eclipse.swt.graphics.Color;
25: import org.eclipse.swt.graphics.Font;
26: import org.eclipse.swt.graphics.Image;
27: import org.eclipse.swt.layout.FormAttachment;
28: import org.eclipse.swt.layout.FormData;
29: import org.eclipse.swt.layout.FormLayout;
30: import org.eclipse.swt.widgets.Composite;
31: import org.eclipse.swt.widgets.Label;
32: import org.eclipse.swt.widgets.ToolBar;
33:
34: /**
35: * The Toolbar at the top of the editor.
36: */
37: public class EditorToolBar extends Composite {
38:
39:         private final ToolBarManager toolBarManager;
40:
41:         private final Color background;
42:
43:         /**
44:          * Creates a new Toolbar.
45:          *
46:          * @param parent The parent
47:          * @param style The Style (SWT.NONE)
48:          * @param titleText The text in the toolbar
49:          * @param toolbarActions a List of actions for the toolbar
50:          */
51:         public EditorToolBar(Composite parent, int style, String titleText, List<Action> toolbarActions) {
52:                 super(parent, style);
53:
54:                 background = new Color(parent.getDisplay(), 207, 222, 238);
55:
56:                 setBackground(background);
57:
58:                 final FormLayout layout = new FormLayout();
59:                 layout.marginHeight = 5;
60:                 layout.marginWidth = 5;
61:                 setLayout(layout);
62:
63:                 // Create the Icon on the Left
64:                 final Label titleImage = new Label(this, SWT.NONE);
65:                 final ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(Activator.getDefault().getBundle()
66:                         .getResource("icons/view.png")); //$NON-NLS-1$
67:                 titleImage.setImage(new Image(parent.getDisplay(), imageDescriptor.getImageData(100)));
68:
69:                 final FormData titleImageData = new FormData();
70:                 final int imageOffset = -titleImage.computeSize(SWT.DEFAULT, SWT.DEFAULT).y / 2;
71:                 titleImageData.top = new FormAttachment(50, imageOffset);
72:                 titleImageData.left = new FormAttachment(0, 10);
73:                 titleImage.setLayoutData(titleImageData);
74:
75:                 // Create the label for the Title Text
76:                 final Label title = new Label(this, SWT.WRAP);
77:                 final FontDescriptor boldDescriptor = FontDescriptor.createFrom(title.getFont()).setHeight(13)
78:                         .setStyle(SWT.BOLD);
79:                 final Font boldFont = boldDescriptor.createFont(title.getDisplay());
80:                 title.setForeground(new Color(parent.getDisplay(), 25, 76, 127));
81:                 title.setFont(boldFont);
82:                 title.setText(titleText);
83:                 final FormData titleData = new FormData();
84:                 titleData.left = new FormAttachment(titleImage, 5, SWT.DEFAULT);
85:                 final int titleHeight = title.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
86:                 titleData.top = new FormAttachment(50, -titleHeight / 2);
87:                 title.setLayoutData(titleData);
88:
89:                 // Create the toolbar and add it to the header
90:                 final ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT);
91:                 final FormData formData = new FormData();
92:                 formData.right = new FormAttachment(100, 0);
93:                 toolBar.setLayoutData(formData);
94:                 toolBar.layout();
95:                 toolBarManager = new ToolBarManager(toolBar);
96:
97:                 // Add the provided actions
98:•                if (toolbarActions != null) {
99:•                        for (final Action a : toolbarActions) {
100:                                 toolBarManager.add(a);
101:                         }
102:                 }
103:
104:                 toolBarManager.update(true);
105:                 this.layout();
106:         }
107:
108:         @Override
109:         public void dispose() {
110:                 background.dispose();
111:                 super.dispose();
112:         }
113:
114: }