1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 01:35:39 +02:00

autotools: Sanitize activators.

Reduce coupling by changing UI bundle to use UI activator and drop UI
getters (e.g. workbench, window, shell) from the core bundle.
Also remove other unused methods.

Change-Id: Ida510d5a0e991c08332a998aefaba5843743172a
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
This commit is contained in:
Alexander Kurtakov 2015-12-02 11:57:07 +02:00
parent 77c74a26ca
commit e061d97881
5 changed files with 17 additions and 214 deletions

View file

@ -22,19 +22,12 @@ import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@ -109,17 +102,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin {
return ref != null ? context.getService(ref) : null;
}
/**
* Returns active shell.
*/
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
return window.getShell();
}
return null;
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
@ -181,17 +163,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin {
return false;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path.
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
}
public static void log(IStatus status) {
ResourcesPlugin.getPlugin().getLog().log(status);
}
@ -200,33 +171,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin {
log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null));
}
public static void logException(Throwable e, final String title, String message) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
IStatus status = null;
if (e instanceof CoreException)
status = ((CoreException) e).getStatus();
else {
if (message == null)
message = e.getMessage();
if (message == null)
message = e.toString();
status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, message, e);
}
ResourcesPlugin.getPlugin().getLog().log(status);
Display display;
display = Display.getCurrent();
if (display == null)
display = Display.getDefault();
final IStatus fstatus = status;
display.asyncExec(() -> ErrorDialog.openError(null, title, null, fstatus));
}
public static void logException(Throwable e) {
logException(e, null, null);
}
public static void log(Throwable e) {
if (e instanceof InvocationTargetException)
e = ((InvocationTargetException) e).getTargetException();
@ -238,63 +182,6 @@ public class AutotoolsPlugin extends AbstractUIPlugin {
log(status);
}
/**
* Utility method with conventions
*/
public static void errorDialog(Shell shell, String title, String message, IStatus s) {
log(s);
// if the 'message' resource string and the IStatus' message are the same,
// don't show both in the dialog
if (s != null && message.equals(s.getMessage())) {
message = null;
}
ErrorDialog.openError(shell, title, message, s);
}
/**
* Utility method with conventions
*/
public static void errorDialog(Shell shell, String title, String message, Throwable t) {
log(t);
IStatus status;
if (t instanceof CoreException) {
status = ((CoreException) t).getStatus();
// if the 'message' resource string and the IStatus' message are the same,
// don't show both in the dialog
if (status != null && message.equals(status.getMessage())) {
message = null;
}
} else {
status = new Status(IStatus.ERROR, AutotoolsPlugin.getUniqueIdentifier(), -1, "Internal Error: ", t); //$NON-NLS-1$
}
ErrorDialog.openError(shell, title, message, status);
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/**
* Returns the active workbench window or <code>null</code> if none
*/
public static IWorkbenchWindow getActiveWorkbenchWindow() {
return getDefault().getWorkbench().getActiveWorkbenchWindow();
}
/**
* Returns the active workbench page or <code>null</code> if none.
*/
public static IWorkbenchPage getActivePage() {
IWorkbenchWindow window= getActiveWorkbenchWindow();
if (window != null) {
return window.getActivePage();
}
return null;
}
/**
* Return set of Autotool configuration options for a given build configuration id.
*

View file

@ -86,7 +86,7 @@ public class AutotoolsConfigurationManager implements IResourceChangeListener {
private AutotoolsConfigurationManager() {
configs = new HashMap<>();
tmpConfigs = new HashMap<>();
AutotoolsPlugin.getWorkspace().addResourceChangeListener(this);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
}
public static AutotoolsConfigurationManager getInstance() {

View file

@ -11,7 +11,6 @@
package org.eclipse.cdt.autotools.ui;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@ -21,9 +20,6 @@ import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
@ -87,17 +83,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin {
return plugin;
}
/**
* Returns active shell.
*/
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getDefault().getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
return window.getShell();
}
return null;
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
@ -114,18 +99,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin {
}
}
/**
* Returns the string from the plugin's resource bundle,
* or 'key' if not found.
*
* @param key the message key
* @param args an array of substituition strings
* @return the resource bundle message
*/
public static String getFormattedString(String key, String[] args) {
return MessageFormat.format(getResourceString(key), (Object[])args);
}
/**
* Returns the plugin's resource bundle,
*/
@ -133,17 +106,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin {
return resourceBundle;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path.
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
}
public static void log(IStatus status) {
ResourcesPlugin.getPlugin().getLog().log(status);
}
@ -152,33 +114,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin {
log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null));
}
public static void logException(Throwable e, final String title, String message) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
IStatus status = null;
if (e instanceof CoreException)
status = ((CoreException) e).getStatus();
else {
if (message == null)
message = e.getMessage();
if (message == null)
message = e.toString();
status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, message, e);
}
ResourcesPlugin.getPlugin().getLog().log(status);
Display display;
display = Display.getCurrent();
if (display == null)
display = Display.getDefault();
final IStatus fstatus = status;
display.asyncExec(() -> ErrorDialog.openError(null, title, null, fstatus));
}
public static void logException(Throwable e) {
logException(e, null, null);
}
public static void log(Throwable e) {
if (e instanceof InvocationTargetException)
e = ((InvocationTargetException) e).getTargetException();
@ -190,38 +125,6 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin {
log(status);
}
/**
* Utility method with conventions
*/
public static void errorDialog(Shell shell, String title, String message, IStatus s) {
log(s);
// if the 'message' resource string and the IStatus' message are the same,
// don't show both in the dialog
if (s != null && message.equals(s.getMessage())) {
message = null;
}
ErrorDialog.openError(shell, title, message, s);
}
/**
* Utility method with conventions
*/
public static void errorDialog(Shell shell, String title, String message, Throwable t) {
log(t);
IStatus status;
if (t instanceof CoreException) {
status = ((CoreException) t).getStatus();
// if the 'message' resource string and the IStatus' message are the same,
// don't show both in the dialog
if (status != null && message.equals(status.getMessage())) {
message = null;
}
} else {
status = new Status(IStatus.ERROR, AutotoolsUIPlugin.getUniqueIdentifier(), -1, "Internal Error: ", t); //$NON-NLS-1$
}
ErrorDialog.openError(shell, title, message, status);
}
/**
* Returns the workspace instance.
*/
@ -246,4 +149,15 @@ public class AutotoolsUIPlugin extends AbstractUIPlugin {
}
return null;
}
/**
* Returns active shell.
*/
public static Shell getActiveWorkbenchShell() {
IWorkbenchWindow window = getActiveWorkbenchWindow();
if (window != null) {
return window.getShell();
}
return null;
}
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.autotools.ui.actions;
import org.eclipse.cdt.autotools.core.AutotoolsPlugin;
import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin;
import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
@ -40,7 +41,7 @@ public abstract class AbstractTargetAction
} else if (fWindow != null) {
return fWindow.getShell();
}
return AutotoolsPlugin.getActiveWorkbenchShell();
return AutotoolsUIPlugin.getActiveWorkbenchShell();
}
protected IContainer getSelectedContainer() {

View file

@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.autotools.ui.editors.automake;
import java.util.ResourceBundle;
import org.eclipse.cdt.autotools.core.AutotoolsPlugin;
import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin;
import org.eclipse.cdt.internal.autotools.ui.MakeUIMessages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ListenerList;
@ -216,8 +217,8 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
if (selection.isEmpty()) {
resetHighlightRange();
} else if (selection instanceof IStructuredSelection){
if (!isActivePart() && AutotoolsPlugin.getActivePage() != null) {
AutotoolsPlugin.getActivePage().bringToTop(this);
if (!isActivePart() && AutotoolsUIPlugin.getActivePage() != null) {
AutotoolsUIPlugin.getActivePage().bringToTop(this);
}
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IDirective) {