-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
488126: PluginUtil for retrieving the current AbstractUIPlugin
Manually changed also a few examples for the new DSL generation Change-Id: I4ed13fb2a730057940c62fb8a882cfeff89221db Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=488126
- Loading branch information
1 parent
e5c34dd
commit 8eb2182
Showing
10 changed files
with
145 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ample/src/org/eclipse/emf/parsley/examples/firstexample/FirstexampleInjectorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.eclipse.emf.parsley.examples.firstexample; | ||
|
||
import static com.google.inject.Guice.createInjector; | ||
import static org.eclipse.emf.parsley.runtime.ui.PluginUtil.getBundle; | ||
import static org.eclipse.emf.parsley.runtime.ui.PluginUtil.getPlugin; | ||
|
||
import com.google.inject.Injector; | ||
|
||
public class FirstexampleInjectorProvider { | ||
|
||
private static Injector injector; | ||
|
||
public static synchronized Injector getInjector() throws Exception { | ||
if (injector == null) { | ||
injector = createInjector( | ||
new FirstexampleGuiceModule(getPlugin(getBundle(FirstexampleInjectorProvider.class)))); | ||
} | ||
return injector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../src/org/eclipse/emf/parsley/examples/mail/accountsview/AccountsviewInjectorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.eclipse.emf.parsley.examples.mail.accountsview; | ||
|
||
import static com.google.inject.Guice.createInjector; | ||
import static org.eclipse.emf.parsley.runtime.ui.PluginUtil.getBundle; | ||
import static org.eclipse.emf.parsley.runtime.ui.PluginUtil.getPlugin; | ||
|
||
import com.google.inject.Injector; | ||
|
||
public class AccountsviewInjectorProvider { | ||
|
||
private static Injector injector; | ||
|
||
public static synchronized Injector getInjector() throws Exception { | ||
if (injector == null) { | ||
injector = createInjector( | ||
new AccountsviewGuiceModule(getPlugin(getBundle(AccountsviewInjectorProvider.class)))); | ||
} | ||
return injector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...lsview/src/org/eclipse/emf/parsley/examples/mail/mailsview/MailsviewInjectorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.eclipse.emf.parsley.examples.mail.mailsview; | ||
|
||
import static com.google.inject.Guice.createInjector; | ||
import static org.eclipse.emf.parsley.runtime.ui.PluginUtil.getBundle; | ||
import static org.eclipse.emf.parsley.runtime.ui.PluginUtil.getPlugin; | ||
|
||
import com.google.inject.Injector; | ||
|
||
public class MailsviewInjectorProvider { | ||
|
||
private static Injector injector; | ||
|
||
public static synchronized Injector getInjector() throws Exception { | ||
if (injector == null) { | ||
injector = createInjector( | ||
new MailsviewGuiceModule(getPlugin(getBundle(MailsviewInjectorProvider.class)))); | ||
} | ||
return injector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...eclipse.emf.parsley.runtime.common/src/org/eclipse/emf/parsley/runtime/ui/PluginUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 RCP Vision (http://www.rcp-vision.com) and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Lorenzo Bettini - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.emf.parsley.runtime.ui; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Dictionary; | ||
|
||
import org.eclipse.ui.plugin.AbstractUIPlugin; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.Constants; | ||
import org.osgi.framework.FrameworkUtil; | ||
|
||
/** | ||
* Utility methods for plug-ins. | ||
* | ||
* @author Lorenzo Bettini - initial API and implementation | ||
* | ||
*/ | ||
public class PluginUtil { | ||
|
||
protected PluginUtil() { | ||
|
||
} | ||
|
||
public static Bundle getBundle(Class<?> classFromBundle) { | ||
return FrameworkUtil.getBundle(classFromBundle); | ||
} | ||
|
||
/** | ||
* Retrieves the {@link AbstractUIPlugin} activator from the specified {@link Bundle}, | ||
* via reflection, assuming that the activator has a static method getDefault returning | ||
* the singleton instance. | ||
* | ||
* @param bundle | ||
* @return | ||
* @throws Exception | ||
*/ | ||
public static AbstractUIPlugin getPlugin(Bundle bundle) throws Exception { | ||
final Dictionary<String, String> headers = bundle.getHeaders(); | ||
String activator = headers.get(Constants.BUNDLE_ACTIVATOR); | ||
Class<?> activatorClass = bundle.loadClass(activator); | ||
Method method = activatorClass.getMethod("getDefault"); | ||
Object activatorInstance = method.invoke(null); | ||
return (AbstractUIPlugin) activatorInstance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters