Revision 2586

tmp/org.txm.rcp/META-INF/MANIFEST.MF (revision 2586)
1 1
Manifest-Version: 1.0
2
Export-Package: junit.extensions,junit.framework,junit.runner,junit.te
3
 xtui,org.apache.commons.cli,org.apache.commons.lang,org.apache.common
4
 s.lang.builder,org.apache.commons.lang.enum,org.apache.commons.lang.e
5
 nums,org.apache.commons.lang.exception,org.apache.commons.lang.math,o
6
 rg.apache.commons.lang.mutable,org.apache.commons.lang.text,org.apach
7
 e.commons.lang.time,org.apache.log4j,org.apache.log4j.chainsaw,org.ap
8
 ache.log4j.config,org.apache.log4j.helpers,org.apache.log4j.jdbc,org.
9
 apache.log4j.jmx,org.apache.log4j.lf5,org.apache.log4j.lf5.util,org.a
10
 pache.log4j.lf5.viewer,org.apache.log4j.lf5.viewer.categoryexplorer,o
11
 rg.apache.log4j.lf5.viewer.configure,org.apache.log4j.net,org.apache.
12
 log4j.nt,org.apache.log4j.or,org.apache.log4j.or.jms,org.apache.log4j
13
 .or.sax,org.apache.log4j.spi,org.apache.log4j.varia,org.apache.log4j.
14
 xml,org.eclipse.jface.fieldassist,org.hamcrest,org.hamcrest.core,org.
15
 hamcrest.internal,org.junit,org.junit.experimental.results,org.junit.
16
 experimental.runners,org.junit.experimental.theories,org.junit.experi
17
 mental.theories.internal,org.junit.experimental.theories.suppliers,or
18
 g.junit.internal,org.junit.internal.builders,org.junit.internal.match
19
 ers,org.junit.internal.requests,org.junit.internal.runners,org.junit.
20
 internal.runners.model,org.junit.internal.runners.statements,org.juni
21
 t.matchers,org.junit.runner,org.junit.runner.manipulation,org.junit.r
22
 unner.notification,org.junit.runners,org.junit.runners.model,org.txm.
23
 rcp,org.txm.rcp.actions,org.txm.rcp.adapters,org.txm.rcp.commands,org
24
 .txm.rcp.commands.editor,org.txm.rcp.commands.function,org.txm.rcp.co
25
 mmands.queryview,org.txm.rcp.commands.workspace,org.txm.rcp.corpuswiz
26
 ard,org.txm.rcp.editors,org.txm.rcp.editors.adaptableDataStructure,or
27
 g.txm.rcp.editors.imports,org.txm.rcp.editors.imports.sections,org.tx
28
 m.rcp.editors.input,org.txm.rcp.editors.listeners,org.txm.rcp.handler
29
 s,org.txm.rcp.handlers.export,org.txm.rcp.handlers.files,org.txm.rcp.
30
 handlers.results,org.txm.rcp.handlers.scripts,org.txm.rcp.jface,org.t
31
 xm.rcp.log,org.txm.rcp.menu,org.txm.rcp.messages,org.txm.rcp.p2.plugi
32
 ns,org.txm.rcp.perspective,org.txm.rcp.preferences,org.txm.rcp.splash
33
 Handlers,org.txm.rcp.svg,org.txm.rcp.swt,org.txm.rcp.swt.dialog,org.t
34
 xm.rcp.swt.listeners,org.txm.rcp.swt.provider,org.txm.rcp.swt.toolbar
35
 ,org.txm.rcp.swt.widget,org.txm.rcp.swt.widget.parameters,org.txm.rcp
36
 .swt.widget.preferences,org.txm.rcp.swt.widget.structures,org.txm.rcp
37
 .testers,org.txm.rcp.utils,org.txm.rcp.views,org.txm.rcp.views.cmdpar
38
 ameters,org.txm.rcp.views.corpora,org.txm.rcp.views.debug,org.txm.rcp
39
 .views.fileexplorer,org.txm.rcp.wizard,swing2swt.layout
2
Export-Package: junit.extensions,
3
 junit.framework,
4
 junit.runner,
5
 junit.textui,
6
 org.apache.commons.cli,
7
 org.apache.commons.lang,
8
 org.apache.commons.lang.builder,
9
 org.apache.commons.lang.enum,
10
 org.apache.commons.lang.enums,
11
 org.apache.commons.lang.exception,
12
 org.apache.commons.lang.math,
13
 org.apache.commons.lang.mutable,
14
 org.apache.commons.lang.text,
15
 org.apache.commons.lang.time,
16
 org.apache.log4j,
17
 org.apache.log4j.chainsaw,
18
 org.apache.log4j.config,
19
 org.apache.log4j.helpers,
20
 org.apache.log4j.jdbc,
21
 org.apache.log4j.jmx,
22
 org.apache.log4j.lf5,
23
 org.apache.log4j.lf5.util,
24
 org.apache.log4j.lf5.viewer,
25
 org.apache.log4j.lf5.viewer.categoryexplorer,
26
 org.apache.log4j.lf5.viewer.configure,
27
 org.apache.log4j.net,
28
 org.apache.log4j.nt,
29
 org.apache.log4j.or,
30
 org.apache.log4j.or.jms,
31
 org.apache.log4j.or.sax,
32
 org.apache.log4j.spi,
33
 org.apache.log4j.varia,
34
 org.apache.log4j.xml,
35
 org.eclipse.jface.fieldassist,
36
 org.hamcrest,
37
 org.hamcrest.core,
38
 org.hamcrest.internal,
39
 org.junit,
40
 org.junit.experimental.results,
41
 org.junit.experimental.runners,
42
 org.junit.experimental.theories,
43
 org.junit.experimental.theories.internal,
44
 org.junit.experimental.theories.suppliers,
45
 org.junit.internal,
46
 org.junit.internal.builders,
47
 org.junit.internal.matchers,
48
 org.junit.internal.requests,
49
 org.junit.internal.runners,
50
 org.junit.internal.runners.model,
51
 org.junit.internal.runners.statements,
52
 org.junit.matchers,
53
 org.junit.runner,
54
 org.junit.runner.manipulation,
55
 org.junit.runner.notification,
56
 org.junit.runners,
57
 org.junit.runners.model,
58
 org.txm.rcp,
59
 org.txm.rcp.actions,
60
 org.txm.rcp.adapters,
61
 org.txm.rcp.commands,
62
 org.txm.rcp.commands.editor,
63
 org.txm.rcp.commands.function,
64
 org.txm.rcp.commands.queryview,
65
 org.txm.rcp.commands.workspace,
66
 org.txm.rcp.corpuswizard,
67
 org.txm.rcp.editors,
68
 org.txm.rcp.editors.adaptableDataStructure,
69
 org.txm.rcp.editors.imports,
70
 org.txm.rcp.editors.imports.sections,
71
 org.txm.rcp.editors.input,
72
 org.txm.rcp.editors.listeners,
73
 org.txm.rcp.handlers,
74
 org.txm.rcp.handlers.export,
75
 org.txm.rcp.handlers.files,
76
 org.txm.rcp.handlers.results,
77
 org.txm.rcp.handlers.scripts,
78
 org.txm.rcp.jface,
79
 org.txm.rcp.log,
80
 org.txm.rcp.menu,
81
 org.txm.rcp.messages,
82
 org.txm.rcp.notifications,
83
 org.txm.rcp.p2.plugins,
84
 org.txm.rcp.perspective,
85
 org.txm.rcp.preferences,
86
 org.txm.rcp.splashHandlers,
87
 org.txm.rcp.svg,
88
 org.txm.rcp.swt,
89
 org.txm.rcp.swt.dialog,
90
 org.txm.rcp.swt.listeners,
91
 org.txm.rcp.swt.provider,
92
 org.txm.rcp.swt.toolbar,
93
 org.txm.rcp.swt.widget,
94
 org.txm.rcp.swt.widget.parameters,
95
 org.txm.rcp.swt.widget.preferences,
96
 org.txm.rcp.swt.widget.structures,
97
 org.txm.rcp.testers,
98
 org.txm.rcp.utils,
99
 org.txm.rcp.views,
100
 org.txm.rcp.views.cmdparameters,
101
 org.txm.rcp.views.corpora,
102
 org.txm.rcp.views.debug,
103
 org.txm.rcp.views.fileexplorer,
104
 org.txm.rcp.wizard,
105
 swing2swt.layout
40 106
Bundle-SymbolicName: org.txm.rcp;singleton:=true
41 107
Bundle-Version: 0.8.0.qualifier
42 108
Bundle-Name: %Bundle-Name
tmp/org.txm.rcp/src/main/java/org/txm/rcp/preferences/RCPPreferences.java (revision 2586)
16 16
	
17 17
//	public static final String PREFERENCES_NODE = FrameworkUtil.getBundle(RCPPreferences.class).getSymbolicName();
18 18

  
19

  
19
	/**
20
	 * enable/disable system notifications when TXM ends a long task
21
	 */
22
	public static final String SHOW_NOTIFICATIONS = "show_notifications"; //$NON-NLS-1$
23
	
20 24
	/** Preference set with the osgi-nl parameter */
21 25
	public static final String CONFIG_LOCALE = "ui_locale"; //$NON-NLS-1$
22 26
	/** Preference set with the -Xms parameter */
......
84 88
		preferences.putBoolean(SHOW_SEVERE_DIALOG, false);
85 89
		preferences.putBoolean(USER_ALERT_DELETE, false);
86 90
		preferences.putBoolean(SAVE_BEFORE_EXECUTION, false);
91
		preferences.putBoolean(SHOW_NOTIFICATIONS, false);
87 92
		
88 93
		preferences.putBoolean(CGU, false);
89 94
		
tmp/org.txm.rcp/src/main/java/org/txm/rcp/preferences/UserPreferencePage.java (revision 2586)
51 51
	protected void createFieldEditors() {
52 52
		this.addField(new BooleanFieldEditor(RCPPreferences.USER_ALERT_DELETE, TXMUIMessages.doNotConfirmToDeleteAnObject, BooleanFieldEditor.SEPARATE_LABEL, this.getFieldEditorParent()));
53 53
		
54
		this.addField(new BooleanFieldEditor(RCPPreferences.SHOW_NOTIFICATIONS, "Show a notification window when TXM ends a long task", BooleanFieldEditor.SEPARATE_LABEL, this.getFieldEditorParent()));
55
		
54 56
		// Auto compute the result when a parameter changes
55 57
		this.addField(new BooleanFieldEditor(RCPPreferences.AUTO_UPDATE_EDITOR, TXMUIMessages.automaticRecomputingWhenChangingAParameter, BooleanFieldEditor.SEPARATE_LABEL, this
56 58
				.getFieldEditorParent()));
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteImportScript.java (revision 2586)
35 35
import org.eclipse.core.runtime.IProgressMonitor;
36 36
import org.eclipse.core.runtime.IStatus;
37 37
import org.eclipse.core.runtime.Status;
38
import org.eclipse.osgi.util.NLS;
38 39
import org.eclipse.swt.SWT;
39 40
import org.eclipse.swt.widgets.Display;
40 41
import org.eclipse.swt.widgets.FileDialog;
......
42 43
import org.eclipse.ui.handlers.HandlerUtil;
43 44
import org.txm.Toolbox;
44 45
import org.txm.core.messages.TXMCoreMessages;
46
import org.txm.core.preferences.TXMPreferences;
45 47
import org.txm.objects.Project;
46 48
import org.txm.rcp.StatusLine;
47 49
import org.txm.rcp.commands.OpenImportForm;
48 50
import org.txm.rcp.commands.RestartTXM;
49 51
import org.txm.rcp.messages.TXMUIMessages;
52
import org.txm.rcp.notifications.SimpleNotification;
53
import org.txm.rcp.preferences.RCPPreferences;
54
import org.txm.rcp.preferences.UserPreferencePage;
50 55
import org.txm.rcp.utils.JobHandler;
51 56
import org.txm.rcp.views.corpora.CorporaView;
52 57
import org.txm.searchengine.cqp.corpus.MainCorpus;
......
94 99
		return null;
95 100
	}
96 101

  
97
//	@Deprecated
98
//	public static JobHandler executeScript(String scriptFilePath,
99
//			File paramFile) {
100
//		BaseOldParameters params = null;
101
//		try {
102
//			params = new BaseOldParameters(paramFile);
103
//		} catch (Exception e1) {
104
//			org.txm.utils.logger.Log.printStackTrace(e1);
105
//			System.out.println("Error while reading import parameters from: "+paramFile);
106
//			return null;
107
//		}
108
//		return executeScript(scriptFilePath, params);
109
//	}
110
	
102
	//	@Deprecated
103
	//	public static JobHandler executeScript(String scriptFilePath,
104
	//			File paramFile) {
105
	//		BaseOldParameters params = null;
106
	//		try {
107
	//			params = new BaseOldParameters(paramFile);
108
	//		} catch (Exception e1) {
109
	//			org.txm.utils.logger.Log.printStackTrace(e1);
110
	//			System.out.println("Error while reading import parameters from: "+paramFile);
111
	//			return null;
112
	//		}
113
	//		return executeScript(scriptFilePath, params);
114
	//	}
115

  
111 116
	/**
112 117
	 * 
113 118
	 * @param scriptFilePath 
......
119 124
		if (project.getImportModuleName() == null) {
120 125
			return null;
121 126
		}
122
		
127

  
123 128
		Display.getDefault().syncExec(new Runnable() {
124 129
			public void run() {	StatusLine.setMessage(TXMUIMessages.importStarted); }
125 130
		});
......
132 137
			Log.severe(TXMUIMessages.errorColonCorporaDirectoryDoesntExistColon+corporadir);
133 138
			return null;
134 139
		}
135
		
136
//		if (CQPSearchEngine.isInitialized()) {
137
//			Toolbox.getEngineManager(EngineType.SEARCH).stopEngines();
138
//		}
139
		
140

  
141
		//		if (CQPSearchEngine.isInitialized()) {
142
		//			Toolbox.getEngineManager(EngineType.SEARCH).stopEngines();
143
		//		}
144
		final long time = System.currentTimeMillis();
140 145
		JobHandler jobhandler = new JobHandler(TXMUIMessages.scriptExecution + " " + project.getImportModuleName()) { //$NON-NLS-1$
141 146
			@Override
142 147
			protected IStatus run(IProgressMonitor monitor) {
143 148
				this.runInit(monitor);
144 149
				try {
145 150
					boolean doUpdate = project.getDoUpdate();
151
					
146 152
					if (project.compute(monitor)) {
147
						
153

  
148 154
						this.releaseSemaphore();
149 155

  
156

  
157

  
150 158
						monitor.done();
151 159
						if (doUpdate) {
152 160
							Log.info(TXMUIMessages.updateDone);
......
160 168
					e.printStackTrace();
161 169
				} finally {
162 170
					System.gc();
163
//					if (!CQPSearchEngine.isInitialized()) {
164
//						try {
165
//							SearchEnginesManager.getCQPSearchEngine().start(monitor);
166
//						} catch (Exception e) {
167
//							// TODO Auto-generated catch block
168
//							e.printStackTrace();
169
//						}
170
//					}
171
					//					if (!CQPSearchEngine.isInitialized()) {
172
					//						try {
173
					//							SearchEnginesManager.getCQPSearchEngine().start(monitor);
174
					//						} catch (Exception e) {
175
					//							// TODO Auto-generated catch block
176
					//							e.printStackTrace();
177
					//						}
178
					//					}
171 179
					syncExec(new Runnable() {
172 180
						@Override
173 181
						public void run() {
182
							if (RCPPreferences.getInstance().getBoolean(RCPPreferences.SHOW_NOTIFICATIONS) 
183
									&& (System.currentTimeMillis() - time) > 60000) {
184
								String message = NLS.bind("The {0} corpus was succesfully imported", project.getName());
185
								if (project.isDirty()) {
186
									message = NLS.bind("The {0} corpus was not imported correctly. Please check console messages.", project.getName());
187
								}
188
								new SimpleNotification(Display.getCurrent(), "Import done", message).open();
189
							}
174 190
							RestartTXM.reloadViews();
175 191
							CorporaView.select(project.getChildren(MainCorpus.class));
176 192
						}
177 193
					});
178 194
				}
179
				
195

  
180 196
				return Status.CANCEL_STATUS;
181 197
			}
182 198
		};
tmp/org.txm.rcp/src/main/java/org/txm/rcp/notifications/AbstractNotificationPopup.java (revision 2586)
1
package org.txm.rcp.notifications;
2

  
3
import org.eclipse.core.runtime.IProgressMonitor;
4
import org.eclipse.core.runtime.IStatus;
5
import org.eclipse.core.runtime.Status;
6
import org.eclipse.core.runtime.jobs.Job;
7
import org.eclipse.jface.resource.JFaceResources;
8
import org.eclipse.jface.resource.LocalResourceManager;
9
import org.eclipse.jface.window.Window;
10
import org.eclipse.swt.SWT;
11
import org.eclipse.swt.events.ControlAdapter;
12
import org.eclipse.swt.events.ControlEvent;
13
import org.eclipse.swt.events.MouseAdapter;
14
import org.eclipse.swt.events.MouseEvent;
15
import org.eclipse.swt.events.MouseTrackAdapter;
16
import org.eclipse.swt.graphics.Color;
17
import org.eclipse.swt.graphics.GC;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Point;
20
import org.eclipse.swt.graphics.Rectangle;
21
import org.eclipse.swt.graphics.Region;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Monitor;
29
import org.eclipse.swt.widgets.Shell;
30

  
31
/**
32
 * A popup window with a title bar and message area for displaying notifications.
33
 * 
34
 * @author Benjamin Pasero
35
 * @author Mik Kersten
36
 * @author Steffen Pingel
37
 * @since 3.7
38
 */
39
public abstract class AbstractNotificationPopup extends Window {
40

  
41
	private static final int TITLE_HEIGHT = 24;
42

  
43
	private static final int MAX_WIDTH = 400;
44

  
45
	private static final int MIN_HEIGHT = 100;
46

  
47
	private static final long DEFAULT_DELAY_CLOSE = 8 * 1000;
48

  
49
	private static final int PADDING_EDGE = 5;
50

  
51
	private long delayClose = DEFAULT_DELAY_CLOSE;
52

  
53
	protected LocalResourceManager resources;
54

  
55
	private final Display display;
56

  
57
	private Shell shell;
58

  
59
	private Region lastUsedRegion;
60

  
61
	private Image lastUsedBgImage;
62

  
63
	private final Job closeJob = new Job("Closing") {
64

  
65
		@Override
66
		protected IStatus run(IProgressMonitor monitor) {
67
			if (!display.isDisposed()) {
68
				display.asyncExec(new Runnable() {
69
					public void run() {
70
						Shell shell = AbstractNotificationPopup.this.getShell();
71
						if (shell == null || shell.isDisposed()) {
72
							return;
73
						}
74

  
75
						if (isMouseOver(shell)) {
76
							scheduleAutoClose();
77
							return;
78
						}
79

  
80
						AbstractNotificationPopup.this.closeFade();
81
					}
82

  
83
				});
84
			}
85
			if (monitor.isCanceled()) {
86
				return Status.CANCEL_STATUS;
87
			}
88

  
89
			return Status.OK_STATUS;
90
		}
91
	};
92

  
93
	private final boolean respectDisplayBounds = true;
94

  
95
	private final boolean respectMonitorBounds = true;
96

  
97
	private boolean fadingEnabled;
98

  
99
	public AbstractNotificationPopup(Display display) {
100
		this(display, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
101
	}
102

  
103
	public AbstractNotificationPopup(Display display, int style) {
104
		super(new Shell(display));
105
		setShellStyle(style);
106

  
107
		this.display = display;
108
		resources = new LocalResourceManager(JFaceResources.getResources());
109
//		initResources();
110

  
111
		closeJob.setSystem(true);
112
	}
113

  
114
	public boolean isFadingEnabled() {
115
		return fadingEnabled;
116
	}
117

  
118
	public void setFadingEnabled(boolean fadingEnabled) {
119
		this.fadingEnabled = fadingEnabled;
120
	}
121

  
122
	/**
123
	 * Override to return a customized name. Default is to return the name of the product, specified by the -name (e.g.
124
	 * "Eclipse SDK") command line parameter that's associated with the product ID (e.g. "org.eclipse.sdk.ide"). Strips
125
	 * the trailing "SDK" for any name, since this part of the label is considered visual noise.
126
	 * 
127
	 * @return the name to be used in the title of the popup.
128
	 */
129
	protected String getPopupShellTitle() {
130
		return "TXM";
131
	}
132

  
133
	protected Image getPopupShellImage(int maximumHeight) {
134
		return null;
135
	}
136

  
137
	/**
138
	 * Override to populate with notifications.
139
	 * 
140
	 * @param parent
141
	 */
142
	protected void createContentArea(Composite parent) {
143
		// empty by default
144
	}
145

  
146
	/**
147
	 * Override to customize the title bar
148
	 */
149
	protected void createTitleArea(Composite parent) {
150
		((GridData) parent.getLayoutData()).heightHint = TITLE_HEIGHT;
151

  
152
		Label titleImageLabel = new Label(parent, SWT.NONE);
153
		titleImageLabel.setImage(getPopupShellImage(TITLE_HEIGHT));
154

  
155
		Label titleTextLabel = new Label(parent, SWT.NONE);
156
		titleTextLabel.setText(getPopupShellTitle());
157
//		titleTextLabel.setForeground(getTitleForeground());
158
//		titleTextLabel.setForeground(color.getTitleText());
159
		titleTextLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true));
160
		titleTextLabel.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
161

  
162
		final Label button = new Label(parent, SWT.NONE);
163
		button.setText("close");
164
		
165
		MouseAdapter closeAdapter = new MouseAdapter() {
166

  
167
			@Override
168
			public void mouseUp(MouseEvent e) {
169
				close();
170
				setReturnCode(CANCEL);
171
			}
172

  
173
		};
174
		button.addMouseListener(closeAdapter);
175
		titleTextLabel.addMouseListener(closeAdapter);
176
		titleImageLabel.addMouseListener(closeAdapter);
177
	}
178

  
179
	@Override
180
	protected void configureShell(Shell newShell) {
181
		super.configureShell(newShell);
182

  
183
		shell = newShell;
184
//		newShell.setBackground(color.getBorder());
185
	}
186

  
187
	@Override
188
	public void create() {
189
		super.create();
190
		addRegion(shell);
191
	}
192

  
193
	private void addRegion(Shell shell) {
194
		Region region = new Region();
195
		Point s = shell.getSize();
196

  
197
		/* Add entire Shell */
198
		region.add(0, 0, s.x, s.y);
199

  
200
		/* Subtract Top-Left Corner */
201
		region.subtract(0, 0, 5, 1);
202
		region.subtract(0, 1, 3, 1);
203
		region.subtract(0, 2, 2, 1);
204
		region.subtract(0, 3, 1, 1);
205
		region.subtract(0, 4, 1, 1);
206

  
207
		/* Subtract Top-Right Corner */
208
		region.subtract(s.x - 5, 0, 5, 1);
209
		region.subtract(s.x - 3, 1, 3, 1);
210
		region.subtract(s.x - 2, 2, 2, 1);
211
		region.subtract(s.x - 1, 3, 1, 1);
212
		region.subtract(s.x - 1, 4, 1, 1);
213

  
214
		/* Subtract Bottom-Left Corner */
215
		region.subtract(0, s.y, 5, 1);
216
		region.subtract(0, s.y - 1, 3, 1);
217
		region.subtract(0, s.y - 2, 2, 1);
218
		region.subtract(0, s.y - 3, 1, 1);
219
		region.subtract(0, s.y - 4, 1, 1);
220

  
221
		/* Subtract Bottom-Right Corner */
222
		region.subtract(s.x - 5, s.y - 0, 5, 1);
223
		region.subtract(s.x - 3, s.y - 1, 3, 1);
224
		region.subtract(s.x - 2, s.y - 2, 2, 1);
225
		region.subtract(s.x - 1, s.y - 3, 1, 1);
226
		region.subtract(s.x - 1, s.y - 4, 1, 1);
227

  
228
		/* Dispose old first */
229
		if (shell.getRegion() != null) {
230
			shell.getRegion().dispose();
231
		}
232

  
233
		/* Apply Region */
234
		shell.setRegion(region);
235

  
236
		/* Remember to dispose later */
237
		lastUsedRegion = region;
238
	}
239

  
240
	private boolean isMouseOver(Shell shell) {
241
		if (display.isDisposed()) {
242
			return false;
243
		}
244
		return shell.getBounds().contains(display.getCursorLocation());
245
	}
246

  
247
	@Override
248
	public int open() {
249
		if (shell == null || shell.isDisposed()) {
250
			shell = null;
251
			create();
252
		}
253

  
254
		constrainShellSize();
255
		shell.setLocation(fixupDisplayBounds(shell.getSize(), shell.getLocation()));
256

  
257
		if (isFadingEnabled()) {
258
			shell.setAlpha(0);
259
		}
260
		shell.setVisible(true);
261
//		fadeJob = AnimationUtil.fadeIn(shell, new IFadeListener() {
262
//			public void faded(Shell shell, int alpha) {
263
//				if (shell.isDisposed()) {
264
//					return;
265
//				}
266
//
267
//				if (alpha == 255) {
268
//					scheduleAutoClose();
269
//				}
270
//			}
271
//		});
272

  
273
		return Window.OK;
274
	}
275

  
276
	protected void scheduleAutoClose() {
277
		if (delayClose > 0) {
278
			closeJob.schedule(delayClose);
279
		}
280
	}
281

  
282
	@Override
283
	protected Control createContents(Composite parent) {
284
		((GridLayout) parent.getLayout()).marginWidth = 1;
285
		((GridLayout) parent.getLayout()).marginHeight = 1;
286

  
287
		/* Outer Composite holding the controls */
288
		final Composite outerCircle = new Composite(parent, SWT.NO_FOCUS);
289
		outerCircle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
290
		outerCircle.setBackgroundMode(SWT.INHERIT_FORCE);
291

  
292
		outerCircle.addControlListener(new ControlAdapter() {
293

  
294
			@Override
295
			public void controlResized(ControlEvent e) {
296
				Rectangle clArea = outerCircle.getClientArea();
297
				lastUsedBgImage = new Image(outerCircle.getDisplay(), clArea.width, clArea.height);
298
				GC gc = new GC(lastUsedBgImage);
299

  
300
				/* Gradient */
301
				drawGradient(gc, clArea);
302

  
303
				/* Fix Region Shape */
304
				fixRegion(gc, clArea);
305

  
306
				gc.dispose();
307

  
308
				Image oldBGImage = outerCircle.getBackgroundImage();
309
				outerCircle.setBackgroundImage(lastUsedBgImage);
310

  
311
				if (oldBGImage != null) {
312
					oldBGImage.dispose();
313
				}
314
			}
315

  
316
			private void drawGradient(GC gc, Rectangle clArea) {
317
//				gc.setForeground(color.getGradientBegin());
318
//				gc.setBackground(color.getGradientEnd());
319
//				gc.fillGradientRectangle(clArea.x, clArea.y, clArea.width, clArea.height, true);
320
			}
321

  
322
			private void fixRegion(GC gc, Rectangle clArea) {
323
//				gc.setForeground(color.getBorder());
324

  
325
				/* Fill Top Left */
326
				gc.drawPoint(2, 0);
327
				gc.drawPoint(3, 0);
328
				gc.drawPoint(1, 1);
329
				gc.drawPoint(0, 2);
330
				gc.drawPoint(0, 3);
331

  
332
				/* Fill Top Right */
333
				gc.drawPoint(clArea.width - 4, 0);
334
				gc.drawPoint(clArea.width - 3, 0);
335
				gc.drawPoint(clArea.width - 2, 1);
336
				gc.drawPoint(clArea.width - 1, 2);
337
				gc.drawPoint(clArea.width - 1, 3);
338

  
339
				/* Fill Bottom Left */
340
				gc.drawPoint(2, clArea.height - 0);
341
				gc.drawPoint(3, clArea.height - 0);
342
				gc.drawPoint(1, clArea.height - 1);
343
				gc.drawPoint(0, clArea.height - 2);
344
				gc.drawPoint(0, clArea.height - 3);
345

  
346
				/* Fill Bottom Right */
347
				gc.drawPoint(clArea.width - 4, clArea.height - 0);
348
				gc.drawPoint(clArea.width - 3, clArea.height - 0);
349
				gc.drawPoint(clArea.width - 2, clArea.height - 1);
350
				gc.drawPoint(clArea.width - 1, clArea.height - 2);
351
				gc.drawPoint(clArea.width - 1, clArea.height - 3);
352
			}
353
		});
354

  
355
		GridLayout layout = new GridLayout(1, false);
356
		layout.marginWidth = 0;
357
		layout.marginHeight = 0;
358
		layout.verticalSpacing = 0;
359

  
360
		outerCircle.setLayout(layout);
361

  
362
		/* Title area containing label and close button */
363
		final Composite titleCircle = new Composite(outerCircle, SWT.NO_FOCUS);
364
		titleCircle.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
365
		titleCircle.setBackgroundMode(SWT.INHERIT_FORCE);
366

  
367
		layout = new GridLayout(4, false);
368
		layout.marginWidth = 3;
369
		layout.marginHeight = 0;
370
		layout.verticalSpacing = 5;
371
		layout.horizontalSpacing = 3;
372

  
373
		titleCircle.setLayout(layout);
374

  
375
		/* Create Title Area */
376
		createTitleArea(titleCircle);
377

  
378
		/* Outer composite to hold content controlls */
379
		Composite outerContentCircle = new Composite(outerCircle, SWT.NONE);
380
		outerContentCircle.setBackgroundMode(SWT.INHERIT_FORCE);
381

  
382
		layout = new GridLayout(1, false);
383
		layout.marginWidth = 0;
384
		layout.marginHeight = 0;
385

  
386
		outerContentCircle.setLayout(layout);
387
		outerContentCircle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
388
		outerContentCircle.setBackground(outerCircle.getBackground());
389

  
390
		/* Middle composite to show a 1px black line around the content controls */
391
		Composite middleContentCircle = new Composite(outerContentCircle, SWT.NO_FOCUS);
392
		middleContentCircle.setBackgroundMode(SWT.INHERIT_FORCE);
393

  
394
		layout = new GridLayout(1, false);
395
		layout.marginWidth = 0;
396
		layout.marginHeight = 0;
397
		layout.marginTop = 1;
398

  
399
		middleContentCircle.setLayout(layout);
400
		middleContentCircle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
401
//		middleContentCircle.setBackground(color.getBorder());
402

  
403
		/* Inner composite containing the content controls */
404
		Composite innerContent = new Composite(middleContentCircle, SWT.NO_FOCUS);
405
		innerContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
406
		innerContent.setBackgroundMode(SWT.INHERIT_FORCE);
407

  
408
		layout = new GridLayout(1, false);
409
		layout.marginWidth = 0;
410
		layout.marginHeight = 5;
411
		layout.marginLeft = 5;
412
		layout.marginRight = 5;
413
		innerContent.setLayout(layout);
414

  
415
		innerContent.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_WHITE));
416

  
417
		/* Content Area */
418
		createContentArea(innerContent);
419

  
420
		setNullBackground(outerCircle);
421

  
422
		return outerCircle;
423
	}
424

  
425
	private void setNullBackground(final Composite outerCircle) {
426
		for (Control c : outerCircle.getChildren()) {
427
			c.setBackground(null);
428
			if (c instanceof Composite) {
429
				setNullBackground((Composite) c);
430
			}
431
		}
432
	}
433

  
434
	@Override
435
	protected void initializeBounds() {
436
		Rectangle clArea = getPrimaryClientArea();
437
		Point initialSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
438
		int height = Math.max(initialSize.y, MIN_HEIGHT);
439
		int width = Math.min(initialSize.x, MAX_WIDTH);
440

  
441
		Point size = new Point(width, height);
442
		shell.setLocation(clArea.width + clArea.x - size.x - PADDING_EDGE, clArea.height + clArea.y - size.y
443
				- PADDING_EDGE);
444
		shell.setSize(size);
445
	}
446

  
447
	private Rectangle getPrimaryClientArea() {
448
		Monitor primaryMonitor = shell.getDisplay().getPrimaryMonitor();
449
		return (primaryMonitor != null) ? primaryMonitor.getClientArea() : shell.getDisplay().getClientArea();
450
	}
451

  
452
	public void closeFade() {
453
//		if (fadeJob != null) {
454
//			fadeJob.cancelAndWait(false);
455
//		}
456
//		fadeJob = AnimationUtil.fadeOut(getShell(), new IFadeListener() {
457
//			public void faded(Shell shell, int alpha) {
458
//				if (!shell.isDisposed()) {
459
//					if (alpha == 0) {
460
//						shell.close();
461
//					} else if (isMouseOver(shell)) {
462
//						if (fadeJob != null) {
463
//							fadeJob.cancelAndWait(false);
464
//						}
465
//						fadeJob = AnimationUtil.fastFadeIn(shell, new IFadeListener() {
466
//							public void faded(Shell shell, int alpha) {
467
//								if (shell.isDisposed()) {
468
//									return;
469
//								}
470
//
471
//								if (alpha == 255) {
472
//									scheduleAutoClose();
473
//								}
474
//							}
475
//						});
476
//					}
477
//				}
478
//			}
479
//		});
480
	}
481

  
482
	@Override
483
	public boolean close() {
484
		resources.dispose();
485
		if (lastUsedRegion != null) {
486
			lastUsedRegion.dispose();
487
		}
488
		if (lastUsedBgImage != null && !lastUsedBgImage.isDisposed()) {
489
			lastUsedBgImage.dispose();
490
		}
491
		return super.close();
492
	}
493

  
494
	public long getDelayClose() {
495
		return delayClose;
496
	}
497

  
498
	public void setDelayClose(long delayClose) {
499
		this.delayClose = delayClose;
500
	}
501

  
502
	private Point fixupDisplayBounds(Point tipSize, Point location) {
503
		if (respectDisplayBounds) {
504
			Rectangle bounds;
505
			Point rightBounds = new Point(tipSize.x + location.x, tipSize.y + location.y);
506

  
507
			if (respectMonitorBounds) {
508
				bounds = shell.getDisplay().getPrimaryMonitor().getBounds();
509
			} else {
510
				bounds = getPrimaryClientArea();
511
			}
512

  
513
			if (!(bounds.contains(location) && bounds.contains(rightBounds))) {
514
				if (rightBounds.x > bounds.x + bounds.width) {
515
					location.x -= rightBounds.x - (bounds.x + bounds.width);
516
				}
517

  
518
				if (rightBounds.y > bounds.y + bounds.height) {
519
					location.y -= rightBounds.y - (bounds.y + bounds.height);
520
				}
521

  
522
				if (location.x < bounds.x) {
523
					location.x = bounds.x;
524
				}
525

  
526
				if (location.y < bounds.y) {
527
					location.y = bounds.y;
528
				}
529
			}
530
		}
531

  
532
		return location;
533
	}
534

  
535
}
536

  
0 537

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/notifications/SimpleNotification.java (revision 2586)
1
package org.txm.rcp.notifications;
2

  
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.layout.GridData;
5
import org.eclipse.swt.layout.GridLayout;
6
import org.eclipse.swt.widgets.Composite;
7
import org.eclipse.swt.widgets.Display;
8
import org.eclipse.swt.widgets.Label;
9

  
10
/**
11
 * Sample Notification Popup Class
12
 */
13
public class SimpleNotification extends AbstractNotificationPopup {
14

  
15
    private String title;
16
	private String message;
17

  
18
	/**
19
     * @param display
20
     */
21
    public SimpleNotification(Display display, String title, String message) {
22
        super(display);
23
        this.title = title;
24
        this.message = message;
25
    }
26
    
27
    @Override
28
    protected void createContentArea(Composite parent) {
29

  
30
        Composite container = new Composite(parent, SWT.NULL);
31

  
32
        GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
33
        container.setLayoutData(data);
34

  
35
        container.setLayout(new GridLayout(1, false));
36

  
37
        Label successMsg = new Label(container, SWT.NULL);
38
        successMsg.setText(message);
39
        
40

  
41
//        new Label(container, SWT.NONE);
42
//        Label testLabel1 = new Label(container, SWT.NONE);
43
//        testLabel1.setText("This is a Test Label");
44
//        FontData fontData = testLabel1.getFont().getFontData()[0];
45
//        Font font = new Font(Display.getCurrent(),
46
//                new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
47
//        testLabel1.setFont(font);
48
//
49
//        String url = "https://www.google.com/";
50
//
51
//        Link restEP = new Link(container, SWT.WRAP | SWT.LEFT);
52
//        restEP.setText(createUrl(url));
53
//        GridData linkData = new GridData();
54
//        linkData.widthHint = 400;
55
//        restEP.setLayoutData(linkData);
56
//        restEP.addSelectionListener(new SelectionAdapter() {
57
//
58
//            @Override
59
//            public void widgetSelected(SelectionEvent e) {
60
//                Program.launch(url);
61
//            }
62
//
63
//        });
64
//            
65
        new Label(container, SWT.NONE);
66
    }
67

  
68
    @Override
69
    protected String getPopupShellTitle() {
70
        return title;
71
    }
72
}
0 73

  

Also available in: Unified diff