|
1 /* |
|
2 * Copyright (c) 2007-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 "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 * Trim Information |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.eventhandler; |
|
20 |
|
21 import org.eclipse.jface.action.IContributionManager; |
|
22 import org.eclipse.swt.SWT; |
|
23 import org.eclipse.swt.layout.GridData; |
|
24 import org.eclipse.swt.layout.GridLayout; |
|
25 import org.eclipse.swt.widgets.Composite; |
|
26 import org.eclipse.swt.widgets.Control; |
|
27 import org.eclipse.swt.widgets.Label; |
|
28 import org.eclipse.ui.menus.WorkbenchWindowControlContribution; |
|
29 |
|
30 /** |
|
31 * Trim Information |
|
32 */ |
|
33 public final class TrimInformation extends WorkbenchWindowControlContribution { |
|
34 /** |
|
35 * Composite of the trim |
|
36 */ |
|
37 private static Composite composite; |
|
38 |
|
39 /** |
|
40 * Text of the trim |
|
41 */ |
|
42 private static Label textLabel; |
|
43 |
|
44 /** |
|
45 * Text inside the trim |
|
46 */ |
|
47 private static String textInTheTrim = ""; //$NON-NLS-1$ |
|
48 |
|
49 /** |
|
50 * Trim parent |
|
51 */ |
|
52 private static IContributionManager trimParent; |
|
53 |
|
54 /* |
|
55 * (non-Javadoc) |
|
56 * |
|
57 * @see org.eclipse.jface.menus.AbstractTrimWidget#dispose() |
|
58 */ |
|
59 @Override |
|
60 public void dispose() { |
|
61 if (composite != null && !composite.isDisposed()) { |
|
62 composite.dispose(); |
|
63 } |
|
64 if (textLabel != null && !textLabel.isDisposed()) { |
|
65 textLabel.dispose(); |
|
66 } |
|
67 composite = null; |
|
68 textLabel = null; |
|
69 } |
|
70 |
|
71 /** |
|
72 * Sets text to label |
|
73 * |
|
74 * @param labelText |
|
75 * text to insert |
|
76 */ |
|
77 public static void setTextToLabel(String labelText) { |
|
78 textInTheTrim = labelText; |
|
79 |
|
80 // Only update the trim parent when there's something in our trim |
|
81 if (!textInTheTrim.equals("")) { //$NON-NLS-1$ |
|
82 trimParent.update(true); |
|
83 |
|
84 // Empty, let's not resize the trim parent but only update the text |
|
85 } else { |
|
86 textLabel.setText(textInTheTrim); |
|
87 } |
|
88 } |
|
89 |
|
90 /* |
|
91 * (non-Javadoc) |
|
92 * |
|
93 * @see |
|
94 * org.eclipse.jface.action.ControlContribution#createControl(org.eclipse |
|
95 * .swt.widgets.Composite) |
|
96 */ |
|
97 @Override |
|
98 protected Control createControl(Composite parent) { |
|
99 trimParent = getParent(); |
|
100 |
|
101 // Create a composite to place the label in |
|
102 composite = new Composite(parent, SWT.NULL); |
|
103 |
|
104 // Give some room around the control |
|
105 GridLayout layout = new GridLayout(); |
|
106 layout.marginHeight = 0; |
|
107 composite.setLayout(layout); |
|
108 |
|
109 // Create a label for the trim. |
|
110 textLabel = new Label(composite, SWT.NULL); |
|
111 textLabel |
|
112 .setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, true)); |
|
113 textLabel.setText(textInTheTrim); |
|
114 return composite; |
|
115 } |
|
116 |
|
117 /* |
|
118 * (non-Javadoc) |
|
119 * |
|
120 * @see org.eclipse.jface.action.ContributionItem#isDynamic() |
|
121 */ |
|
122 @Override |
|
123 public boolean isDynamic() { |
|
124 return true; |
|
125 } |
|
126 } |