Skip to content

Commit 414b735

Browse files
committed
ZSTD-4724 [Notifications] Invalid thread access when closing Studio
1 parent c6b3bde commit 414b735

File tree

8 files changed

+79
-267
lines changed

8 files changed

+79
-267
lines changed

org.zend.core.notifications/src/org/zend/core/notifications/Activator.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
import org.eclipse.jface.resource.ImageDescriptor;
1313
import org.eclipse.swt.events.DisposeEvent;
1414
import org.eclipse.swt.events.DisposeListener;
15+
import org.eclipse.swt.graphics.Image;
1516
import org.eclipse.swt.widgets.Display;
1617
import org.eclipse.swt.widgets.Shell;
1718
import org.eclipse.ui.IWorkbenchWindow;
1819
import org.eclipse.ui.PlatformUI;
1920
import org.eclipse.ui.plugin.AbstractUIPlugin;
2021
import org.osgi.framework.BundleContext;
21-
import org.zend.core.notifications.util.Fonts;
22-
import org.zend.core.notifications.util.ImageCache;
2322

2423
/**
2524
* The activator class controls the plug-in life cycle
@@ -65,16 +64,6 @@ public void start(BundleContext context) throws Exception {
6564
public void stop(BundleContext context) throws Exception {
6665
plugin = null;
6766
super.stop(context);
68-
69-
Display d = Display.getDefault();
70-
if (! d.isDisposed()) {
71-
d.asyncExec(new Runnable() {
72-
public void run() {
73-
ImageCache.dispose();
74-
Fonts.dispose();
75-
}
76-
});
77-
}
7867
}
7968

8069
/**
@@ -113,6 +102,33 @@ public static ImageDescriptor getImageDescriptor(String path) {
113102
return imageDescriptorFromPlugin(PLUGIN_ID, path);
114103
}
115104

105+
public Image getImage(String path) {
106+
Image image = getImageRegistry().get(path);
107+
if (image == null) {
108+
getImageRegistry().put(path, getImageDescriptor(path));
109+
image = getImageRegistry().get(path);
110+
}
111+
return image;
112+
}
113+
114+
/**
115+
* Returns an image for notification close button focused out.
116+
*
117+
* @return {@link Image} or null if image was not found
118+
*/
119+
public static Image getCloseOut() {
120+
return Activator.getDefault().getImage("icons/close.gif"); //$NON-NLS-1$
121+
}
122+
123+
/**
124+
* Returns an image for notification close button focused in.
125+
*
126+
* @return {@link Image} or null if image was not found
127+
*/
128+
public static Image getCloseIn() {
129+
return Activator.getDefault().getImage("icons/close_active.gif"); //$NON-NLS-1$
130+
}
131+
116132
private Shell getWorkbenchShell(Shell previousShell) {
117133
IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
118134
.getWorkbenchWindows();

org.zend.core.notifications/src/org/zend/core/notifications/internal/ui/MessageWithHelpBody.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
import org.eclipse.swt.widgets.Composite;
1919
import org.eclipse.swt.widgets.Link;
2020
import org.eclipse.swt.widgets.Menu;
21-
import org.eclipse.ui.PlatformUI;
2221
import org.zend.core.notifications.Activator;
2322
import org.zend.core.notifications.ui.IActionListener;
2423
import org.zend.core.notifications.ui.IBody;
2524
import org.zend.core.notifications.ui.NotificationSettings;
26-
import org.zend.core.notifications.util.FontName;
2725
import org.zend.core.notifications.util.Fonts;
2826

2927
/**
@@ -54,13 +52,13 @@ public Composite createContent(Composite container,
5452
layout.horizontalSpacing = layout.verticalSpacing = 2;
5553
composite.setLayout(layout);
5654
Link text = new Link(composite, SWT.WRAP);
57-
text.setFont(Fonts.get(FontName.DEFAULT));
55+
text.setFont(Fonts.DEFAULT.getFont());
5856
text.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, true));
5957
text.setText(message);
6058
if (helpContextId != null) {
6159
text.addSelectionListener(new SelectionAdapter() {
6260
@Override
63-
public void widgetSelected(SelectionEvent selectionEvent) {
61+
public void widgetSelected(SelectionEvent selectionEvent) {
6462
org.eclipse.swt.program.Program.launch(helpContextId);
6563
}
6664
});

org.zend.core.notifications/src/org/zend/core/notifications/internal/ui/Notification.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
import org.zend.core.notifications.ui.NotificationSettings;
4848
import org.zend.core.notifications.util.Colors;
4949
import org.zend.core.notifications.util.EnvironmentUtils;
50-
import org.zend.core.notifications.util.FontName;
5150
import org.zend.core.notifications.util.Fonts;
52-
import org.zend.core.notifications.util.ImageCache;
5351

5452
public class Notification implements IActionListener, INotification {
5553

@@ -291,7 +289,7 @@ protected void createBody(Composite container) {
291289
layout.horizontalSpacing = layout.verticalSpacing = 2;
292290
body.setLayout(layout);
293291
Label text = new Label(body, SWT.WRAP);
294-
text.setFont(Fonts.get(FontName.DEFAULT));
292+
text.setFont(Fonts.DEFAULT.getFont());
295293
text.setLayoutData(new GridData(GridData.FILL_BOTH));
296294
text.setForeground(Display.getDefault().getSystemColor(
297295
SWT.COLOR_BLACK));
@@ -348,7 +346,7 @@ protected void createTitle(Composite container) {
348346
titleLabel.setText(settings.getTitle());
349347
titleLabel.setForeground(Colors.getColorRegistry().get(
350348
"org.eclipse.ui.workbench.INACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
351-
titleLabel.setFont(Fonts.get(FontName.BOLD));
349+
titleLabel.setFont(Fonts.BOLD.getFont());
352350
}
353351

354352
protected void createImage(Composite container) {
@@ -367,22 +365,22 @@ protected void createClose(Composite container) {
367365
final CLabel button = new CLabel(container, SWT.NONE);
368366
button.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING
369367
| GridData.HORIZONTAL_ALIGN_BEGINNING));
370-
button.setImage(ImageCache.getCloseOut());
368+
button.setImage(Activator.getCloseOut());
371369
button.addMouseTrackListener(new MouseTrackAdapter() {
372370
@Override
373371
public void mouseEnter(MouseEvent e) {
374-
button.setImage(ImageCache.getCloseIn());
372+
button.setImage(Activator.getCloseIn());
375373
}
376374

377375
@Override
378376
public void mouseExit(MouseEvent e) {
379-
button.setImage(ImageCache.getCloseOut());
377+
button.setImage(Activator.getCloseOut());
380378
}
381379
});
382380
button.addMouseListener(new MouseAdapter() {
383381
@Override
384382
public void mouseUp(MouseEvent e) {
385-
button.setImage(ImageCache.getCloseOut());
383+
button.setImage(Activator.getCloseOut());
386384
hide();
387385
statusChanged();
388386
}

org.zend.core.notifications/src/org/zend/core/notifications/internal/ui/progress/ProgressNotification.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.zend.core.notifications.NotificationManager;
2929
import org.zend.core.notifications.internal.ui.Notification;
3030
import org.zend.core.notifications.ui.NotificationSettings;
31-
import org.zend.core.notifications.util.FontName;
3231
import org.zend.core.notifications.util.Fonts;
3332

3433
/**
@@ -92,7 +91,7 @@ protected void createBody(Composite container) {
9291
layout.horizontalSpacing = layout.verticalSpacing = 2;
9392
composite.setLayout(layout);
9493
message = new Label(composite, SWT.WRAP);
95-
message.setFont(Fonts.get(FontName.DEFAULT));
94+
message.setFont(Fonts.DEFAULT.getFont());
9695
message.setLayoutData(new GridData(GridData.FILL_BOTH));
9796
message.setForeground(Display.getDefault().getSystemColor(
9897
SWT.COLOR_BLACK));

org.zend.core.notifications/src/org/zend/core/notifications/ui/NotificationType.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
package org.zend.core.notifications.ui;
99

1010
import org.eclipse.swt.graphics.Image;
11-
import org.zend.core.notifications.util.ImageCache;
11+
import org.zend.core.notifications.Activator;
1212

1313
/**
1414
* Represents notification type.
@@ -18,11 +18,11 @@
1818
*/
1919
public enum NotificationType {
2020

21-
ERROR(ImageCache.getImage("icons/error.png")), //$NON-NLS-1$
21+
ERROR(Activator.getDefault().getImage("icons/error.png")), //$NON-NLS-1$
2222

23-
WARNING(ImageCache.getImage("icons/warn.png")), //$NON-NLS-1$
23+
WARNING(Activator.getDefault().getImage("icons/warn.png")), //$NON-NLS-1$
2424

25-
INFO(ImageCache.getImage("icons/info.png")), //$NON-NLS-1$
25+
INFO(Activator.getDefault().getImage("icons/info.png")), //$NON-NLS-1$
2626

2727
CUSTOM(null);
2828

org.zend.core.notifications/src/org/zend/core/notifications/util/FontName.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 38 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,38 @@
1-
/*******************************************************************************
2-
* Copyright (c) 2012 Zend Technologies Ltd.
3-
* All rights reserved. This program and the accompanying materials
4-
* are made available under the terms of the Eclipse Public License v1.0
5-
* which accompanies this distribution, and is available at
6-
* http://www.eclipse.org/legal/epl-v10.html
7-
*******************************************************************************/
8-
package org.zend.core.notifications.util;
9-
10-
import static org.zend.core.notifications.util.FontName.BOLD;
11-
import static org.zend.core.notifications.util.FontName.DEFAULT;
12-
import static org.zend.core.notifications.util.FontName.ITALIC;
13-
import static org.zend.core.notifications.util.FontName.ITALIC_BOLD;
14-
15-
import java.util.HashMap;
16-
import java.util.Map;
17-
import java.util.Set;
18-
19-
import org.eclipse.jface.resource.JFaceResources;
20-
import org.eclipse.swt.SWT;
21-
import org.eclipse.swt.graphics.Font;
22-
import org.eclipse.swt.graphics.FontData;
23-
import org.eclipse.swt.widgets.Display;
24-
25-
/**
26-
* Caching class for fonts. Also deals with re-creating fonts should they have
27-
* been disposed when the caller asks for a font.
28-
*
29-
* @author Wojciech Galanciak, 2012
30-
*
31-
*/
32-
public class Fonts {
33-
34-
private static Map<String, Font> cache = new HashMap<String, Font>();
35-
36-
static {
37-
Display.getDefault().syncExec(new Runnable() {
38-
39-
public void run() {
40-
Font defaultFont = JFaceResources.getFontRegistry()
41-
.defaultFont();
42-
cache.put(DEFAULT.getName(), defaultFont);
43-
Font boldFont = JFaceResources.getFontRegistry().getBold(
44-
JFaceResources.DEFAULT_FONT);
45-
cache.put(BOLD.getName(), boldFont);
46-
Font italicFont = JFaceResources.getFontRegistry().getItalic(
47-
JFaceResources.DEFAULT_FONT);
48-
cache.put(ITALIC.getName(), italicFont);
49-
Font italicBold = new Font(Display.getCurrent(),
50-
getModifiedFontData(get(ITALIC).getFontData(), SWT.BOLD
51-
| SWT.ITALIC));
52-
cache.put(ITALIC_BOLD.getName(), italicBold);
53-
}
54-
});
55-
}
56-
57-
/**
58-
* Disposes all fonts and clears out the cache. Never call this unless you
59-
* are shutting down your code/client/etc.
60-
*/
61-
public static void dispose() {
62-
if (cache.size() > 0) {
63-
Set<String> keys = cache.keySet();
64-
for (String key : keys) {
65-
Font font = cache.get(key);
66-
if (font != null && !font.isDisposed()) {
67-
font.dispose();
68-
}
69-
}
70-
}
71-
cache.clear();
72-
}
73-
74-
/**
75-
* Get font for specified {@link FontName}.
76-
*
77-
* @param name
78-
* font name
79-
* @return font
80-
*/
81-
public static Font get(FontName name) {
82-
return cache.get(name.getName());
83-
}
84-
85-
/**
86-
* Get font for specified name.
87-
*
88-
* @param name
89-
* font name
90-
* @return font or <code>null</code> if font with specified name is
91-
* unavailable
92-
*/
93-
public static Font get(String name) {
94-
return cache.get(name);
95-
}
96-
97-
/**
98-
* Add new font to change with specified name.
99-
*
100-
* @param name
101-
* new font name
102-
* @param font
103-
* @return <code>true</code> if font added successfully; otherwise return
104-
* <code>false</code>
105-
*/
106-
public static boolean add(String name, Font font) {
107-
if (cache.containsKey(name)) {
108-
return false;
109-
}
110-
cache.put(name, font);
111-
return true;
112-
}
113-
114-
private static FontData[] getModifiedFontData(FontData[] baseData, int style) {
115-
FontData[] styleData = new FontData[baseData.length];
116-
for (int i = 0; i < styleData.length; i++) {
117-
FontData base = baseData[i];
118-
styleData[i] = new FontData(base.getName(), base.getHeight(),
119-
base.getStyle() | style);
120-
}
121-
122-
return styleData;
123-
}
124-
125-
}
1+
/*******************************************************************************
2+
* Copyright (c) 2012 Zend Technologies Ltd.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*******************************************************************************/
8+
package org.zend.core.notifications.util;
9+
10+
import org.eclipse.jface.resource.JFaceResources;
11+
import org.eclipse.swt.graphics.Font;
12+
13+
/**
14+
* Set of default fonts available in {@link Fonts} cache.
15+
*
16+
* @author Wojciech Galanciak, 2012
17+
*
18+
*/
19+
public enum Fonts {
20+
21+
DEFAULT(JFaceResources.getFontRegistry().defaultFont()),
22+
23+
BOLD(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT)),
24+
25+
ITALIC(JFaceResources.getFontRegistry().getItalic(
26+
JFaceResources.DEFAULT_FONT));
27+
28+
private Font font;
29+
30+
private Fonts(Font font) {
31+
this.font = font;
32+
}
33+
34+
public Font getFont() {
35+
return font;
36+
}
37+
38+
}

0 commit comments

Comments
 (0)