Skip to content

Commit 4d020f1

Browse files
author
jantje
committed
move UI stuff to sloeber.ui
1 parent 8d80ab0 commit 4d020f1

File tree

5 files changed

+77
-73
lines changed

5 files changed

+77
-73
lines changed

io.sloeber.core/META-INF/MANIFEST.MF

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ Require-Bundle: org.eclipse.cdt.managedbuilder.core,
2020
org.eclipse.equinox.security,
2121
org.eclipse.core.runtime,
2222
org.apache.commons.io;bundle-version="2.0.0",
23-
org.eclipse.ui.ide,
24-
org.eclipse.ui,
25-
org.eclipse.debug.ui,
26-
org.eclipse.ui.console,
27-
org.eclipse.ui.workbench,
2823
org.junit;bundle-version="4.12.0",
29-
org.slf4j.api;bundle-version="1.7.2"
24+
org.slf4j.api;bundle-version="1.7.2",
25+
org.eclipse.core.resources;bundle-version="3.13.700",
26+
org.eclipse.ui;bundle-version="3.117.0",
27+
org.eclipse.ui.console,
28+
org.eclipse.debug.core
3029
Export-Package: cc.arduino.packages;x-internal:=true,
3130
cc.arduino.packages.discoverers;x-internal:=true,
3231
cc.arduino.packages.ssh;x-internal:=true,

io.sloeber.core/src/io/sloeber/core/Activator.java

+5-56
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
import org.eclipse.core.runtime.IProgressMonitor;
1616
import org.eclipse.core.runtime.IStatus;
1717
import org.eclipse.core.runtime.Platform;
18+
import org.eclipse.core.runtime.Plugin;
1819
import org.eclipse.core.runtime.Status;
1920
import org.eclipse.core.runtime.content.IContentType;
2021
import org.eclipse.core.runtime.content.IContentTypeManager;
2122
import org.eclipse.core.runtime.content.IContentTypeSettings;
22-
import org.eclipse.core.runtime.jobs.IJobManager;
2323
import org.eclipse.core.runtime.jobs.Job;
2424
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2525
import org.eclipse.core.runtime.preferences.InstanceScope;
26-
import org.eclipse.ui.plugin.AbstractUIPlugin;
2726
import org.osgi.framework.BundleContext;
2827
import org.osgi.service.prefs.BackingStoreException;
2928
import org.osgi.service.prefs.Preferences;
@@ -38,28 +37,15 @@
3837
import io.sloeber.core.listeners.IndexerListener;
3938
import io.sloeber.core.managers.InternalPackageManager;
4039

41-
abstract class FamilyJob extends Job {
42-
static final String MY_FAMILY = "myJobFamily"; //$NON-NLS-1$
43-
44-
public FamilyJob(String name) {
45-
super(name);
46-
}
47-
48-
@Override
49-
public boolean belongsTo(Object family) {
50-
return family == MY_FAMILY;
51-
}
52-
53-
}
5440

5541
/**
5642
* generated code
5743
*
5844
* @author Jan Baeyens
5945
*
6046
*/
61-
@SuppressWarnings({ "nls", "unused" })
62-
public class Activator extends AbstractUIPlugin {
47+
@SuppressWarnings({ "nls" })
48+
public class Activator extends Plugin {
6349
// preference nodes
6450
public static final String NODE_ARDUINO = "io.sloeber.arduino";
6551
// TOFIX I think the fix below for unix users is no longer needed and we no
@@ -69,10 +55,7 @@ public class Activator extends AbstractUIPlugin {
6955

7056
// The shared instance
7157
private static final String FLAG_START = "F" + "s" + "S" + "t" + "a" + "t" + "u" + "s";
72-
private static final String UPLOAD_FLAG = "F" + "u" + "S" + "t" + "a" + "t" + "u" + "s";
73-
private static final String BUILD_FLAG = "F" + "b" + "S" + "t" + "a" + "t" + "u" + "s";
74-
private static final String LOCAL_FLAG = "l" + FLAG_START;
75-
private static final String HELP_LOC = "https://www.baeyens.it/eclipse/remind.php";
58+
7659

7760
private static Activator instance;
7861
protected char[] uri = { 'h', 't', 't', 'p', 's', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't',
@@ -98,7 +81,6 @@ public void start(BundleContext context) throws Exception {
9881
if (Const.isLinux && System.getProperty(ENV_KEY_GNU_SERIAL_PORTS) == null) {
9982
System.setProperty(ENV_KEY_GNU_SERIAL_PORTS, ENV_VALUE_GNU_SERIAL_PORTS_LINUX);
10083
}
101-
remind();
10284

10385
}
10486

@@ -271,9 +253,7 @@ protected IStatus run(IProgressMonitor monitor) {
271253
*/
272254
@Override
273255
public void stop(BundleContext context) throws Exception {
274-
IJobManager jobMan = Job.getJobManager();
275-
jobMan.cancel(FamilyJob.MY_FAMILY);
276-
jobMan.join(FamilyJob.MY_FAMILY, null);
256+
277257
instance = null;
278258
super.stop(context);
279259
}
@@ -374,37 +354,6 @@ private static void addFileAssociations() {
374354

375355
}
376356

377-
static void remind() {
378-
379-
Job job = new FamilyJob("pluginReminder") {
380-
@Override
381-
protected IStatus run(IProgressMonitor monitor) {
382357

383-
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
384-
int curFsStatus = myScope.getInt(FLAG_START, 0);
385-
int curFuStatus = myScope.getInt(UPLOAD_FLAG, 0);
386-
int curFbStatus = myScope.getInt(BUILD_FLAG, 0);
387-
int curFsiStatus = curFsStatus + curFuStatus + curFbStatus;
388-
int lastFsiStatus = myScope.getInt(LOCAL_FLAG, 0);
389-
final int trigger = 30;
390-
if ((curFsiStatus - lastFsiStatus) < 0) {
391-
lastFsiStatus = curFsiStatus - (trigger + 1);
392-
}
393-
if ((curFsiStatus - lastFsiStatus) >= trigger) {
394-
myScope.putInt(LOCAL_FLAG, curFsiStatus);
395-
try {
396-
myScope.flush();
397-
} catch (BackingStoreException e) {
398-
// this should not happen
399-
}
400-
PleaseHelp.doHelp(HELP_LOC);
401-
}
402-
remind();
403-
return Status.OK_STATUS;
404-
}
405-
};
406-
job.setPriority(Job.DECORATE);
407-
job.schedule(60000);
408-
}
409358

410359
}

io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.sloeber.core.api;
22

33
import java.io.File;
4-
import java.lang.reflect.InvocationTargetException;
54
import java.net.URI;
65
import java.util.ArrayList;
76
import java.util.List;
@@ -32,6 +31,7 @@
3231
import org.eclipse.core.resources.IWorkspaceRoot;
3332
import org.eclipse.core.resources.ResourcesPlugin;
3433
import org.eclipse.core.runtime.CoreException;
34+
import org.eclipse.core.runtime.ICoreRunnable;
3535
import org.eclipse.core.runtime.IPath;
3636
import org.eclipse.core.runtime.IProgressMonitor;
3737
import org.eclipse.core.runtime.IStatus;
@@ -42,8 +42,6 @@
4242
import org.eclipse.core.runtime.SubMonitor;
4343
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
4444
import org.eclipse.core.runtime.preferences.InstanceScope;
45-
import org.eclipse.ui.actions.WorkspaceModifyOperation;
46-
4745
import io.sloeber.core.Activator;
4846
import io.sloeber.core.InternalBoardDescriptor;
4947
import io.sloeber.core.Messages;
@@ -582,9 +580,9 @@ public IProject createProject(String projectName, URI projectURI, CodeDescriptor
582580
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
583581
final IProject newProjectHandle = root.getProject(realProjectName);
584582
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
585-
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
583+
ICoreRunnable runnable = new ICoreRunnable() {
586584
@Override
587-
protected void execute(IProgressMonitor internalMonitor) throws CoreException {
585+
public void run(IProgressMonitor internalMonitor) throws CoreException {
588586
try {
589587
// Create the base project
590588
IWorkspaceDescription workspaceDesc = workspace.getDescription();
@@ -650,8 +648,8 @@ protected void execute(IProgressMonitor internalMonitor) throws CoreException {
650648

651649
try {
652650
IndexerController.doNotIndex(newProjectHandle);
653-
op.run(monitor);
654-
} catch (InvocationTargetException | InterruptedException e) {
651+
workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor);
652+
} catch (Exception e) {
655653
Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(),
656654
"Project creation failed: " + newProjectHandle.getName(),e)); //$NON-NLS-1$
657655
}

io.sloeber.ui/src/io/sloeber/ui/Activator.java

+61-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import org.eclipse.core.runtime.IProgressMonitor;
44
import org.eclipse.core.runtime.IStatus;
55
import org.eclipse.core.runtime.Status;
6+
import org.eclipse.core.runtime.jobs.IJobManager;
67
import org.eclipse.core.runtime.jobs.Job;
8+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
9+
import org.eclipse.core.runtime.preferences.InstanceScope;
710
import org.eclipse.jface.resource.ImageDescriptor;
811
import org.eclipse.jface.resource.ResourceLocator;
912
import org.eclipse.ui.plugin.AbstractUIPlugin;
1013
import org.eclipse.ui.progress.UIJob;
1114
import org.eclipse.ui.statushandlers.StatusManager;
1215
import org.osgi.framework.BundleContext;
13-
16+
import org.osgi.service.prefs.BackingStoreException;
1417
import io.sloeber.core.api.LibraryManager;
1518
import io.sloeber.ui.helpers.MyPreferences;
1619
import io.sloeber.ui.listeners.MyLibraryInstallHandler;
@@ -22,12 +25,31 @@
2225
* @author Jan Baeyens
2326
*
2427
*/
28+
@SuppressWarnings("nls")
2529
public class Activator extends AbstractUIPlugin {
30+
static abstract class FamilyJob extends Job {
31+
static final String MY_FAMILY = "myJobFamily"; //$NON-NLS-1$
32+
33+
public FamilyJob(String name) {
34+
super(name);
35+
}
2636

37+
@Override
38+
public boolean belongsTo(Object family) {
39+
return family == MY_FAMILY;
40+
}
41+
42+
}
2743
private static final String PLUGIN_ID = "io.sloeber.core.ui"; //$NON-NLS-1$
44+
public static final String NODE_ARDUINO = "io.sloeber.arduino";
2845
private static Activator instance;
2946
private static BundleContext myContext;
30-
47+
// The shared instance
48+
private static final String FLAG_START = "F" + "s" + "S" + "t" + "a" + "t" + "u" + "s";
49+
private static final String UPLOAD_FLAG = "F" + "u" + "S" + "t" + "a" + "t" + "u" + "s";
50+
private static final String BUILD_FLAG = "F" + "b" + "S" + "t" + "a" + "t" + "u" + "s";
51+
private static final String LOCAL_FLAG = "l" + FLAG_START;
52+
private static final String HELP_LOC = "https://www.baeyens.it/eclipse/remind.php";
3153
/**
3254
* This is a wrapper method to quickly make the dough code that is the basis
3355
* of the io.sloeber.core.managers and io.sloeber.core.managers.ui to work.
@@ -115,11 +137,47 @@ public void start(BundleContext context) throws Exception {
115137
instance = this;
116138
initializeImportantVariables();
117139
runGUIRegistration();
140+
remind();
141+
118142
}
119143

120144
@Override
121145
public void stop(BundleContext context) throws Exception {
122-
// nothing to do here
146+
IJobManager jobMan = Job.getJobManager();
147+
jobMan.cancel(FamilyJob.MY_FAMILY);
148+
jobMan.join(FamilyJob.MY_FAMILY, null);
149+
}
150+
151+
static void remind() {
123152

153+
Job job = new FamilyJob("pluginReminder") { //$NON-NLS-1$
154+
@Override
155+
protected IStatus run(IProgressMonitor monitor) {
156+
157+
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
158+
int curFsStatus = myScope.getInt(FLAG_START, 0);
159+
int curFuStatus = myScope.getInt(UPLOAD_FLAG, 0);
160+
int curFbStatus = myScope.getInt(BUILD_FLAG, 0);
161+
int curFsiStatus = curFsStatus + curFuStatus + curFbStatus;
162+
int lastFsiStatus = myScope.getInt(LOCAL_FLAG, 0);
163+
final int trigger = 30;
164+
if ((curFsiStatus - lastFsiStatus) < 0) {
165+
lastFsiStatus = curFsiStatus - (trigger + 1);
166+
}
167+
if ((curFsiStatus - lastFsiStatus) >= trigger) {
168+
myScope.putInt(LOCAL_FLAG, curFsiStatus);
169+
try {
170+
myScope.flush();
171+
} catch (BackingStoreException e) {
172+
// this should not happen
173+
}
174+
PleaseHelp.doHelp(HELP_LOC);
175+
}
176+
remind();
177+
return Status.OK_STATUS;
178+
}
179+
};
180+
job.setPriority(Job.DECORATE);
181+
job.schedule(60000);
124182
}
125183
}

io.sloeber.core/src/io/sloeber/core/PleaseHelp.java renamed to io.sloeber.ui/src/io/sloeber/ui/PleaseHelp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.sloeber.core;
1+
package io.sloeber.ui;
22

33
import org.eclipse.core.runtime.Platform;
44
import org.eclipse.jface.dialogs.Dialog;

0 commit comments

Comments
 (0)