use of org.picocontainer.MutablePicoContainer in project android by JetBrains.
the class AndroidTestCase method registerProjectComponent.
@NotNull
protected <T> T registerProjectComponent(@NotNull Class<T> key, @NotNull T instance) {
MutablePicoContainer picoContainer = (MutablePicoContainer) getProject().getPicoContainer();
@SuppressWarnings("unchecked") T old = (T) picoContainer.getComponentInstance(key.getName());
picoContainer.unregisterComponent(key.getName());
picoContainer.registerComponentInstance(key.getName(), instance);
return old;
}
use of org.picocontainer.MutablePicoContainer in project intellij-community by JetBrains.
the class ExtensionsImplTest method testTryPicoContainer.
@Test
public void testTryPicoContainer() {
DefaultPicoContainer rootContainer = new DefaultPicoContainer();
rootContainer.registerComponentInstance("plugin1", new DefaultPicoContainer(rootContainer));
rootContainer.registerComponentInstance("plugin2", new DefaultPicoContainer(rootContainer));
MutablePicoContainer container1 = (MutablePicoContainer) rootContainer.getComponentInstance("plugin1");
MutablePicoContainer container2 = (MutablePicoContainer) rootContainer.getComponentInstance("plugin2");
container1.registerComponentImplementation("component1", MyComponent1.class);
container1.registerComponentImplementation("component1.1", MyComponent1.class);
container2.registerComponentImplementation("component2", MyComponent2.class);
MyInterface1 testInstance = new MyInterface1() {
@Override
public void run() {
}
};
rootContainer.registerComponentInstance(testInstance);
MyComponent1 component1 = (MyComponent1) container1.getComponentInstance("component1");
assertEquals(testInstance, component1.testObject);
rootContainer.registerComponentInstance("component1", component1);
MyComponent1 component11 = (MyComponent1) container1.getComponentInstance("component1.1");
rootContainer.registerComponentInstance("component11", component11);
MyComponent2 component2 = (MyComponent2) container2.getComponentInstance("component2");
assertEquals(testInstance, component2.testObject);
assertTrue(Arrays.asList(component2.comp1).contains(component1));
assertTrue(Arrays.asList(component2.comp1).contains(component11));
rootContainer.registerComponentInstance("component2", component2);
rootContainer.registerComponentImplementation(MyTestComponent.class);
MyTestComponent testComponent = (MyTestComponent) rootContainer.getComponentInstance(MyTestComponent.class);
assertTrue(Arrays.asList(testComponent.comp1).contains(component1));
assertTrue(Arrays.asList(testComponent.comp1).contains(component11));
assertEquals(component2, testComponent.comp2);
}
use of org.picocontainer.MutablePicoContainer in project intellij-plugins by JetBrains.
the class HbParserTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
final MutablePicoContainer appContainer = getApplication().getPicoContainer();
appContainer.registerComponentInstance(PropertiesComponent.class.getName(), PropertiesComponentImpl.create());
appContainer.registerComponentInstance(TemplateDataLanguageMappings.class.getName(), new TemplateDataLanguageMappings(getProject()));
appContainer.registerComponentInstance(TemplateDataLanguagePatterns.class.getName(), new TemplateDataLanguagePatterns());
addExplicitExtension(LanguageParserDefinitions.INSTANCE, HbLanguage.INSTANCE, new HbParseDefinition());
}
use of org.picocontainer.MutablePicoContainer in project intellij-plugins by JetBrains.
the class BaseEditorAction method update.
public void update(AnActionEvent e) {
FileEditorManager editorManager = FileEditorManager.getInstance(getProject(e));
Editor editor = editorManager.getSelectedTextEditor();
T command = getCommand(e);
MutablePicoContainer container = getContainer(e);
if (command != null && editor != null && container != null) {
VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
if (file != null) {
VFile vFile = VFSUtil.createFileFrom(file, editor.getProject());
if (vFile == null) {
return;
}
command.setVFile(vFile);
setUser(container, command);
prepareCommand(command, editor, container);
}
}
super.update(e);
}
use of org.picocontainer.MutablePicoContainer in project intellij-plugins by JetBrains.
the class SearchHistoryAction method update.
public void update(AnActionEvent e) {
super.update(e);
Project project = getProject(e);
MutablePicoContainer container = getContainer(project);
SearchHistoryCommand command = getCommand(e);
User selectedUser;
if (container != null && project != null && command != null) {
boolean focused = false;
if (IDEtalkMessagesWindowImpl.PLACE_TOOLBAR.equals(e.getPlace())) {
IDEtalkMessagesWindow messagesWindow = project.getComponent(IDEtalkMessagesWindow.class);
selectedUser = messagesWindow.getSelectedUser();
focused = messagesWindow.hasFocus();
} else {
UserListComponent userList = (UserListComponent) container.getComponentInstanceOfType(UserListComponent.class);
selectedUser = userList.getSelectedUser();
focused = userList.getComponent().hasFocus();
}
command.setUser(selectedUser);
e.getPresentation().setEnabled(command.isEnabled() && focused);
}
}
Aggregations