blob: 3877c8c737e31ff677c19183e1b0cbbff4a9544c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*******************************************************************************
* Copyright (c) 2018 Remain Software
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* wim.jongman@remainsoftware.com - initial API and implementation
*******************************************************************************/
package org.eclipse.tips.ide.internal;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.AbstractSourceProvider;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.progress.UIJob;
/**
* Internal class to source a new boolean variable in the IDE called "newtips".
*
*/
public class TipSourceProvider extends AbstractSourceProvider {
private boolean fNewTips;
public TipSourceProvider() {
}
@Override
public void dispose() {
}
@Override
public Map<?, ?> getCurrentState() {
Map<Object, Object> currentState = new HashMap<>();
currentState.put(Constants.SOURCE_UNREAD_TIPS, new Boolean(fNewTips));
return currentState;
}
@Override
public String[] getProvidedSourceNames() {
return new String[] { Constants.SOURCE_UNREAD_TIPS };
}
/**
* Propagate the new status of the <code>newtips</code> variable but always
* layouts all workbench windows to update the trim status.
*
* @param newTips
* true if there are new tips, false if there are no more new tips.
*/
public synchronized void setStatus(boolean newTips) {
boolean changed = fNewTips != newTips;
if (changed) {
fNewTips = newTips;
}
layoutWorkbench(changed);
}
private void layoutWorkbench(boolean changed) {
UIJob job = new UIJob(PlatformUI.getWorkbench().getDisplay(), "Tip of the Day. Layout Shell") {
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
if (changed) {
fireSourceChanged(ISources.ACTIVE_WORKBENCH_WINDOW, getCurrentState());
}
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
System.out.println("layout on " + window + " -> " + fNewTips);
window.getShell().layout(true, true);
}
return Status.OK_STATUS;
}
};
job.schedule(5000); // allow the workbench to settle in.
}
}
|