Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKalyan Prasad Tatavarthi2019-02-12 10:54:23 +0000
committerDani Megert2019-03-05 14:29:54 +0000
commit5f38ded6c00993ba75f3834c25de97962dfef1cc (patch)
tree665e0786482060b53dd0511e3ba2d8250030212c
parent7a767c492d4e07c831b16dd870cc60571037d796 (diff)
downloadeclipse.jdt.ui-5f38ded6c00993ba75f3834c25de97962dfef1cc.tar.gz
eclipse.jdt.ui-5f38ded6c00993ba75f3834c25de97962dfef1cc.tar.xz
eclipse.jdt.ui-5f38ded6c00993ba75f3834c25de97962dfef1cc.zip
Bug 544257 - [12][quick fix] Enable preview features should openP20190306-0525
preferences only when defaults are not used Modified the current fix to have 2 quick fixes available. 1) Enable Preview features in project preferences if present or workspace preferences and rebuild. 2) open corresponding preference/properties page as before. Change-Id: I9a65605fd0db186757c586c1bfa8ef7e0ea94f6c Signed-off-by: Kalyan Prasad Tatavarthi <kalyan_prasad@in.ibm.com>
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java6
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties10
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java125
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java1
4 files changed, 127 insertions, 15 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java
index f23dc1fb3d..7dcc8c5df3 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.java
@@ -444,5 +444,11 @@ public final class CorrectionMessages extends NLS {
public static String NullAnnotationsCorrectionProcessor_change_local_variable_to_nonNull;
public static String NullAnnotationsCorrectionProcessor_create_packageInfo_with_defaultnullness;
public static String PreviewFeaturesSubProcessor_enable_preview_features;
+ public static String PreviewFeaturesSubProcessor_enable_preview_features_workspace;
public static String PreviewFeaturesSubProcessor_enable_preview_features_info;
+ public static String PreviewFeaturesSubProcessor_enable_preview_features_workspace_info;
+ public static String PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features;
+ public static String PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features_info;
+ public static String PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features;
+ public static String PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features_info;
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties
index cedd57bc43..0212c9b1c1 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/CorrectionMessages.properties
@@ -478,5 +478,11 @@ VarargsWarningsSubProcessor_remove_safevarargs_label=Remove @SafeVarargs
NullAnnotationsCorrectionProcessor_change_local_variable_to_nonNull=Declare ''{0}'' as ''@{1}'' to see the root problem
NullAnnotationsCorrectionProcessor_create_packageInfo_with_defaultnullness=Add package-info.java with ''@{0}''
-PreviewFeaturesSubProcessor_enable_preview_features=Enable preview features
-PreviewFeaturesSubProcessor_enable_preview_features_info=Open the Java &gt; Compiler preference page to enable preview features
+PreviewFeaturesSubProcessor_enable_preview_features=Enable preview features on project properties
+PreviewFeaturesSubProcessor_enable_preview_features_workspace=Enable preview features on workspace preferences
+PreviewFeaturesSubProcessor_enable_preview_features_info=Enable preview features on Java &gt; Compiler properties page
+PreviewFeaturesSubProcessor_enable_preview_features_workspace_info=Enable preview features on Java &gt; Compiler preference page
+PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features=Open compiler preferences or properties
+PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features_info=Open Java &gt; Compiler properties or preference page to enable preview features
+PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features=Open project compiler properties
+PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features_info=Open Java &gt; Compiler properties page to enable preview features
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java
index 00e39ee720..c4d103b770 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/PreviewFeaturesSubProcessor.java
@@ -17,16 +17,21 @@
*******************************************************************************/
package org.eclipse.jdt.internal.ui.text.correction;
+import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -35,8 +40,10 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.progress.IProgressService;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.corext.util.Messages;
@@ -45,35 +52,107 @@ import org.eclipse.jdt.ui.text.java.IInvocationContext;
import org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal;
import org.eclipse.jdt.ui.text.java.correction.ICommandAccess;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.jdt.internal.ui.dialogs.OptionalMessageDialog;
import org.eclipse.jdt.internal.ui.preferences.ComplianceConfigurationBlock;
import org.eclipse.jdt.internal.ui.preferences.CompliancePreferencePage;
import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock;
import org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock.Key;
import org.eclipse.jdt.internal.ui.text.java.hover.JavaHoverMessages;
+import org.eclipse.jdt.internal.ui.util.CoreUtility;
public class PreviewFeaturesSubProcessor {
private static final String CONFIGURE_COMPILER_PROBLEM_SEVERITY_DIALOG_ID= "configure_compiler_settings_dialog_id"; //$NON-NLS-1$
+
+ private static class EnablePreviewFeatureProposal extends ChangeCorrectionProposal implements IWorkspaceRunnable {
+
+ private final IJavaProject fJavaProject;
+ private IProject fProject;
+ private Job fUpdateJob;
+ private boolean fChangeOnWorkspace;
+
+
+ public EnablePreviewFeatureProposal(String name, IJavaProject project, boolean changeOnWorkspace, int relevance) {
+ super(name, null, relevance, JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE));
+ fJavaProject= project;
+ fUpdateJob= null;
+ fChangeOnWorkspace= changeOnWorkspace;
+ if (fJavaProject != null) {
+ fProject= fJavaProject.getProject();
+ }
+
+ }
+
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
+ fUpdateJob= CoreUtility.getBuildJob(fChangeOnWorkspace ? null : fProject.getProject());
+ }
+
+ @Override
+ public void apply(IDocument document) {
+ if (fJavaProject == null) {
+ return;
+ }
+ if (fChangeOnWorkspace) {
+ Hashtable<String, String> map= JavaCore.getOptions();
+ map.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ JavaCore.setOptions(map);
+ } else {
+ Map<String, String> map= fJavaProject.getOptions(false);
+ map.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED);
+ fJavaProject.setOptions(map);
+ }
+ try {
+ IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
+ progressService.run(true, true, new WorkbenchRunnableAdapter(this));
+ } catch (InvocationTargetException e) {
+ JavaPlugin.log(e);
+ } catch (InterruptedException e) {
+ return;
+ }
+ if (fUpdateJob != null) {
+ fUpdateJob.schedule();
+ }
+ }
+
+ @Override
+ public String getAdditionalProposalInfo(IProgressMonitor monitor) {
+ if (fChangeOnWorkspace) {
+ return CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_workspace_info;
+ }else {
+ return CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_info;
+ }
+
+ }
+ }
- public static void getEnablePreviewFeaturesProposal(IInvocationContext context, Collection<ICommandAccess> proposals) {
-
- ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features, null, IProposalRelevance.ENABLE_PREVIEW_FEATURES,
+ public static void getOpenCompliancePageToEnablePreviewFeaturesProposal(IInvocationContext context, Collection<ICommandAccess> proposals) {
+
+ IProject project= null;
+ IJavaProject javaProject= context.getCompilationUnit().getJavaProject();
+ if (javaProject != null) {
+ project= javaProject.getProject();
+ }
+
+ Key[] keys= ComplianceConfigurationBlock.getKeys(javaProject != null);
+ boolean hasProjectSpecificOptions= OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
+
+ String label= CorrectionMessages.PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features;
+ if (hasProjectSpecificOptions) {
+ label= CorrectionMessages.PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features;
+ }
+
+ ChangeCorrectionProposal proposal= new ChangeCorrectionProposal(label, null, IProposalRelevance.ENABLE_PREVIEW_FEATURES,
JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)) {
@Override
public void apply(IDocument document) {
- IProject project= null;
- IJavaProject javaProject= context.getCompilationUnit().getJavaProject();
- if (javaProject != null) {
- project= javaProject.getProject();
- }
+
Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
-
boolean usePropertyPage;
- Key[] keys= ComplianceConfigurationBlock.getKeys(javaProject != null);
- boolean hasProjectSpecificOptions= OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
-
+
if (!hasProjectSpecificOptions) {
String message= Messages.format(
JavaHoverMessages.ProblemHover_chooseCompilerSettingsTypeDialog_message,
@@ -120,10 +199,30 @@ public class PreviewFeaturesSubProcessor {
@Override
public String getAdditionalProposalInfo(IProgressMonitor monitor) {
- return CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_info;
+ String additionalProposalInfo= CorrectionMessages.PreviewFeaturesSubProcessor_open_compliance_page_enable_preview_features_info;
+ if (hasProjectSpecificOptions) {
+ additionalProposalInfo= CorrectionMessages.PreviewFeaturesSubProcessor_open_compliance_properties_page_enable_preview_features_info;
+ }
+ return additionalProposalInfo;
}
};
proposals.add(proposal);
}
+
+ public static void getEnablePreviewFeaturesProposal(IInvocationContext context, Collection<ICommandAccess> proposals) {
+ IJavaProject javaProject= context.getCompilationUnit().getJavaProject();
+ if (javaProject != null) {
+ IProject project= javaProject.getProject();
+ Key[] keys= ComplianceConfigurationBlock.getKeys(true);
+ boolean changeOnWorkspace = !OptionsConfigurationBlock.hasProjectSpecificOptions(project, keys, null);
+ String label= CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features;
+ if (changeOnWorkspace) {
+ label= CorrectionMessages.PreviewFeaturesSubProcessor_enable_preview_features_workspace;
+ }
+ EnablePreviewFeatureProposal enableProposal= new EnablePreviewFeatureProposal(label, javaProject, changeOnWorkspace, IProposalRelevance.ENABLE_PREVIEW_FEATURES);
+ proposals.add(enableProposal);
+ }
+ }
+
}
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
index 94c81fab95..7c029f10e8 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/correction/QuickFixProcessor.java
@@ -848,6 +848,7 @@ public class QuickFixProcessor implements IQuickFixProcessor {
break;
case IProblem.PreviewFeatureDisabled:
PreviewFeaturesSubProcessor.getEnablePreviewFeaturesProposal(context, proposals);
+ PreviewFeaturesSubProcessor.getOpenCompliancePageToEnablePreviewFeaturesProposal(context, proposals);
break;
default:
}

Back to the top