Skip to content

Commit df8c02c

Browse files
BananeweizenCalixte
authored andcommitted
have progress icon for checkstyle jobs
1 parent d44c3df commit df8c02c

File tree

5 files changed

+72
-15
lines changed

5 files changed

+72
-15
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
//
19+
//============================================================================
20+
21+
package net.sf.eclipsecs.core.jobs;
22+
23+
import org.eclipse.core.resources.WorkspaceJob;
24+
import org.eclipse.core.runtime.jobs.ISchedulingRule;
25+
26+
/**
27+
* Super class of all jobs that invoke Checkstyle. Avoids concurrent invocations and styles the progress UI.
28+
*
29+
*/
30+
public abstract class AbstractCheckJob extends WorkspaceJob implements ISchedulingRule {
31+
/**
32+
* The job family marker is used by the progress service to provide different icons.
33+
*/
34+
public static final Object CHECKSTYLE_JOB_FAMILY = new Object();
35+
36+
public AbstractCheckJob(String name) {
37+
super(name);
38+
}
39+
40+
@Override
41+
public final boolean isConflicting(ISchedulingRule rule) {
42+
return rule instanceof AuditorJob || rule instanceof RunCheckstyleOnFilesJob;
43+
}
44+
45+
@Override
46+
public boolean belongsTo(Object family) {
47+
if (CHECKSTYLE_JOB_FAMILY.equals(family)) {
48+
return true;
49+
}
50+
51+
return super.belongsTo(family);
52+
}
53+
54+
}

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/jobs/AuditorJob.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import net.sf.eclipsecs.core.util.CheckstylePluginException;
2727

2828
import org.eclipse.core.resources.IProject;
29-
import org.eclipse.core.resources.WorkspaceJob;
3029
import org.eclipse.core.runtime.CoreException;
3130
import org.eclipse.core.runtime.IProgressMonitor;
3231
import org.eclipse.core.runtime.IStatus;
@@ -40,7 +39,7 @@
4039
*
4140
* @author Lars Ködderitzsch
4241
*/
43-
public class AuditorJob extends WorkspaceJob implements ISchedulingRule {
42+
public class AuditorJob extends AbstractCheckJob {
4443

4544
private IProject mProject;
4645

@@ -66,11 +65,6 @@ public boolean contains(ISchedulingRule arg0) {
6665
return arg0 instanceof AuditorJob;
6766
}
6867

69-
@Override
70-
public boolean isConflicting(ISchedulingRule arg0) {
71-
return arg0 instanceof AuditorJob || arg0 instanceof RunCheckstyleOnFilesJob;
72-
}
73-
7468
@Override
7569
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
7670

net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/jobs/RunCheckstyleOnFilesJob.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.eclipse.core.resources.IFile;
3838
import org.eclipse.core.resources.IProject;
3939
import org.eclipse.core.resources.IncrementalProjectBuilder;
40-
import org.eclipse.core.resources.WorkspaceJob;
4140
import org.eclipse.core.runtime.CoreException;
4241
import org.eclipse.core.runtime.IProgressMonitor;
4342
import org.eclipse.core.runtime.IStatus;
@@ -49,7 +48,7 @@
4948
*
5049
* @author Lars Ködderitzsch
5150
*/
52-
public class RunCheckstyleOnFilesJob extends WorkspaceJob implements ISchedulingRule {
51+
public class RunCheckstyleOnFilesJob extends AbstractCheckJob {
5352

5453
private List<IFile> mFilesToCheck;
5554

@@ -85,11 +84,6 @@ public boolean contains(ISchedulingRule arg0) {
8584
return arg0 instanceof RunCheckstyleOnFilesJob;
8685
}
8786

88-
@Override
89-
public boolean isConflicting(ISchedulingRule arg0) {
90-
return arg0 instanceof RunCheckstyleOnFilesJob || arg0 instanceof AuditorJob;
91-
}
92-
9387
@Override
9488
public final IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
9589

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPlugin.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashSet;
2626
import java.util.Locale;
2727

28+
import net.sf.eclipsecs.core.jobs.AbstractCheckJob;
2829
import net.sf.eclipsecs.core.util.CheckstyleLog;
2930
import net.sf.eclipsecs.core.util.ExtensionClassLoader;
3031
import net.sf.eclipsecs.ui.properties.filter.CheckFileOnOpenPartListener;
@@ -45,6 +46,7 @@
4546
import org.eclipse.ui.IWorkbenchWindow;
4647
import org.eclipse.ui.PlatformUI;
4748
import org.eclipse.ui.plugin.AbstractUIPlugin;
49+
import org.eclipse.ui.progress.IProgressService;
4850
import org.osgi.framework.BundleContext;
4951

5052
/**
@@ -140,11 +142,21 @@ public void run() {
140142
}
141143

142144
workbench.addWindowListener(mWindowListener);
145+
registerProgressIcon();
143146
}
144147
});
145148

146149
}
147150

151+
protected void registerProgressIcon() {
152+
IProgressService service = PlatformUI.getWorkbench().getProgressService();
153+
if (service == null) {
154+
return;
155+
}
156+
service.registerIconForFamily(CheckstyleUIPluginImages.CHECKSTYLE_ICON.getImageDescriptor(),
157+
AbstractCheckJob.CHECKSTYLE_JOB_FAMILY);
158+
}
159+
148160
@Override
149161
public void stop(BundleContext context) throws Exception {
150162

net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/CheckstyleUIPluginImages.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ public enum CheckstyleUIPluginImages {
9393
/** Image descriptor for the refresh icon. */
9494
REFRESH_ICON(() -> ResourceLocator.imageDescriptorFromBundle("org.eclipse.search",
9595
"platform:/plugin/org.eclipse.search/icons/full/elcl16/refresh.png")
96-
.orElse(MARKER_ERROR.getImageDescriptor()));
96+
.orElse(MARKER_ERROR.getImageDescriptor())),
97+
/** Image descriptor for the checkstyle project icon. */
98+
CHECKSTYLE_ICON(() -> AbstractUIPlugin.imageDescriptorFromPlugin(CheckstyleUIPlugin.PLUGIN_ID,
99+
"icons/checkstyle_command.png"));
97100

98101
/**
99102
* lazy creation factory

0 commit comments

Comments
 (0)