Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2015-10-23 19:44:09 +0000
committerGerrit Code Review @ Eclipse.org2015-11-16 19:30:41 +0000
commit1fb5209632d10fb024fb7e2bf3b99b563628403c (patch)
tree59f935e32df886472c72e08f52b16a3c0d6047b8
parent0a2bdb625a76d5ee4dcf766c430e9826d7cfce13 (diff)
downloadorg.eclipse.mylyn.commons-e_4_5_m_3_18_x.tar.gz
org.eclipse.mylyn.commons-e_4_5_m_3_18_x.tar.xz
org.eclipse.mylyn.commons-e_4_5_m_3_18_x.zip
480539: Neon: org.eclipse.ui.internal.util.Util.getAdapter removedR_3_18_0e_4_5_m_3_18_x
Change-Id: Ie9612472980ee81b718d289488bcf1e0a9a7764d Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=480539
-rw-r--r--org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryUi.java4
-rw-r--r--org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryUiUtil.java31
-rw-r--r--org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/PlatformUiUtil.java26
3 files changed, 55 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryUi.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryUi.java
index f6bd3b88..a7cf2a81 100644
--- a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryUi.java
+++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/commons/repositories/ui/RepositoryUi.java
@@ -18,6 +18,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.mylyn.commons.ui.dialogs.ValidatableWizardDialog;
import org.eclipse.mylyn.internal.commons.repositories.ui.Messages;
import org.eclipse.mylyn.internal.commons.repositories.ui.RepositoriesUiPlugin;
+import org.eclipse.mylyn.internal.commons.repositories.ui.RepositoryUiUtil;
import org.eclipse.mylyn.internal.commons.repositories.ui.wizards.NewRepositoryWizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
@@ -25,7 +26,6 @@ import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.internal.LegacyResourceSupport;
-import org.eclipse.ui.internal.util.Util;
/**
* @author Steffen Pingel
@@ -64,7 +64,7 @@ public final class RepositoryUi {
IWorkbenchPart part = workbenchWindow.getPartService().getActivePart();
if (part instanceof IEditorPart) {
IEditorInput input = ((IEditorPart) part).getEditorInput();
- Object resource = Util.getAdapter(input, resourceClass);
+ Object resource = RepositoryUiUtil.adapt(input, resourceClass);
if (resource != null) {
selectionToPass = new StructuredSelection(resource);
}
diff --git a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryUiUtil.java b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryUiUtil.java
index 4cd155c3..06d21553 100644
--- a/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryUiUtil.java
+++ b/org.eclipse.mylyn.commons.repositories.ui/src/org/eclipse/mylyn/internal/commons/repositories/ui/RepositoryUiUtil.java
@@ -11,15 +11,20 @@
package org.eclipse.mylyn.internal.commons.repositories.ui;
+import java.lang.reflect.Method;
+
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore;
import org.eclipse.mylyn.commons.repositories.core.auth.UnavailableException;
+import org.eclipse.mylyn.commons.ui.PlatformUiUtil;
import org.eclipse.mylyn.internal.commons.repositories.core.LocationService;
import org.eclipse.mylyn.internal.commons.repositories.core.RepositoriesCoreInternal;
import org.eclipse.osgi.util.NLS;
+import org.osgi.framework.Bundle;
public class RepositoryUiUtil {
@@ -34,9 +39,31 @@ public class RepositoryUiUtil {
try {
store.testAvailability();
} catch (UnavailableException e) {
- StatusHandler.log(new Status(IStatus.ERROR, RepositoriesCoreInternal.ID_PLUGIN, NLS.bind(
- "Credential store not available with ID {0}", id), e)); //$NON-NLS-1$
+ StatusHandler.log(new Status(IStatus.ERROR, RepositoriesCoreInternal.ID_PLUGIN,
+ NLS.bind("Credential store not available with ID {0}", id), e)); //$NON-NLS-1$
page.setErrorMessage(Messages.RepositoryUiUtil_secure_storage_unavailable);
}
}
+
+ @SuppressWarnings({ "restriction", "unchecked" })
+ public static <T> T adapt(Object sourceObject, Class<T> adapter) {
+ try {
+ if (PlatformUiUtil.isNeonOrLater()) {
+ Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$
+ Class<?> clazz = bundle.loadClass("org.eclipse.core.runtime.Adapters"); //$NON-NLS-1$
+ Method adaptMethod = clazz.getMethod("adapt", new Class[] { Object.class, Class.class }); //$NON-NLS-1$
+ Object result = adaptMethod.invoke(clazz, sourceObject, adapter);
+ return (T) result;
+ } else {
+ Bundle bundle = Platform.getBundle("org.eclipse.ui.workbench"); //$NON-NLS-1$
+ Class<?> clazz = bundle.loadClass("org.eclipse.ui.internal.util.Util"); //$NON-NLS-1$
+ Method adaptMethod = clazz.getMethod("getAdapter", new Class[] { Object.class, Class.class }); //$NON-NLS-1$
+ Object result = adaptMethod.invoke(clazz, sourceObject, adapter);
+ return (T) result;
+ }
+ } catch (Exception e) {
+ StatusHandler.log(new Status(IStatus.ERROR, RepositoriesUiPlugin.ID_PLUGIN, "Could not adapt", e)); //$NON-NLS-1$
+ }
+ return null;
+ }
}
diff --git a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/PlatformUiUtil.java b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/PlatformUiUtil.java
index 04e368a3..98da028a 100644
--- a/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/PlatformUiUtil.java
+++ b/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/commons/ui/PlatformUiUtil.java
@@ -33,6 +33,7 @@ public class PlatformUiUtil {
private static class Eclipse36Checker {
public static final boolean result;
+
static {
boolean methodAvailable = false;
try {
@@ -62,7 +63,8 @@ public class PlatformUiUtil {
}
public static int getToolTipXShift() {
- if ("gtk".equals(SWT.getPlatform()) || "carbon".equals(SWT.getPlatform()) || "cocoa".equals(SWT.getPlatform())) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if ("gtk".equals(SWT.getPlatform()) || "carbon".equals(SWT.getPlatform()) //$NON-NLS-1$//$NON-NLS-2$
+ || "cocoa".equals(SWT.getPlatform())) { //$NON-NLS-1$
return -26;
} else {
return -23;
@@ -127,7 +129,7 @@ public class PlatformUiUtil {
* If a a section does not use a toolbar as its text client the spacing between the section header and client will
* be different from other sections. This method returns the value to set as the vertical spacing on those sections
* to align the vertical position of section clients.
- *
+ *
* @return value for {@link org.eclipse.ui.forms.widgets.Section#clientVerticalSpacing}
*/
public static int getToolbarSectionClientVerticalSpacing() {
@@ -204,4 +206,24 @@ public class PlatformUiUtil {
return internalBrowserAvailable.booleanValue();
}
+ /**
+ * @since 3.18
+ */
+ public static boolean isNeonOrLater() {
+ Bundle bundle = Platform.getBundle("org.eclipse.platform"); //$NON-NLS-1$
+ if (bundle != null) {
+ String versionString = (String) bundle.getHeaders().get("Bundle-Version"); //$NON-NLS-1$
+ Version version = new Version(versionString);
+ return version.compareTo(new Version("4.6.0.v20151020-0800")) >= 0; //$NON-NLS-1$
+ }
+ bundle = Platform.getBundle("org.eclipse.swt"); //$NON-NLS-1$
+ if (bundle != null) {
+ String versionString = (String) bundle.getHeaders().get("Bundle-Version"); //$NON-NLS-1$
+ Version version = new Version(versionString);
+ return version.compareTo(new Version("3.105.0.v20151020-0634")) >= 0; //$NON-NLS-1$
+ }
+ return false;
+
+ }
+
}

Back to the top