<artifactId>org.argeo.eclipse.ui.jcr.explorer</artifactId>
<name>Commons JCR Explorer</name>
<packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${version.maven-bundle-plugin}</version>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
- <Import-Package>
- org.eclipse.swt,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
<dependencies>
-
- <!-- Argeo Eclipse distribution (common dependencies for both RAP and RCP) -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.common</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
<dependency>
<groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.ui</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- JCR -->
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.jcr</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.jcr</artifactId>
+ <artifactId>org.argeo.eclipse.ui.jucr</artifactId>
<version>0.2.3-SNAPSHOT</version>
</dependency>
<version>0.2.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
-
- <!-- Argeo Commons -->
- <dependency>
- <groupId>org.argeo.commons.basic</groupId>
- <artifactId>org.argeo.basic.nodeps</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
- </dependency>
</dependencies>
</project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.eclipse.ui.jcr</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-#Sat Jan 22 14:25:47 CET 2011
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+++ /dev/null
-#Sat Jan 22 14:25:47 CET 2011
-eclipse.preferences.version=1
-pluginProject.extensions=false
-resolve.requirebundle=false
+++ /dev/null
-source.. = src/main/java/
-output.. = target/classes/
-bin.includes = META-INF/,\
- .
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.argeo.commons.eclipse</groupId>
- <version>0.2.3-SNAPSHOT</version>
- <artifactId>plugins</artifactId>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>org.argeo.eclipse.ui.jcr</artifactId>
- <name>Commons Eclipse UI JCR</name>
- <packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${version.maven-bundle-plugin}</version>
- <configuration>
- <instructions>
- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
- <Import-Package>
- org.eclipse.swt,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
-
- <!-- Argeo Eclipse distribution (common dependencies for both RAP and RCP) -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.common</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.ui</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- JCR -->
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.jcr</artifactId>
- </dependency>
- <dependency>
- <groupId>org.argeo.commons.server</groupId>
- <artifactId>org.argeo.server.jcr</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- RCP only dependency, needed at compile time -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- Argeo Commons -->
- <dependency>
- <groupId>org.argeo.commons.basic</groupId>
- <artifactId>org.argeo.basic.nodeps</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
- </dependency>
- </dependencies>
-</project>
+++ /dev/null
-package org.argeo.eclipse.ui.jcr.commands;
-
-import org.argeo.eclipse.ui.jcr.editors.JcrQueryEditorInput;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/** Open a JCR query editor. */
-public class OpenGenericJcrQueryEditor extends AbstractHandler {
- private String editorId;
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- try {
- JcrQueryEditorInput editorInput = new JcrQueryEditorInput("", null);
- IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(
- event).getActivePage();
- activePage.openEditor(editorInput, editorId);
- } catch (Exception e) {
- throw new ExecutionException("Cannot open editor", e);
- }
- return null;
- }
-
- public void setEditorId(String editorId) {
- this.editorId = editorId;
- }
-
-}
+++ /dev/null
-package org.argeo.eclipse.ui.jcr.editors;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.QueryResult;
-import javax.jcr.query.Row;
-import javax.jcr.query.RowIterator;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.GenericTableComparator;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
-
-/** Executes any JCR query. */
-public abstract class AbstractJcrQueryEditor extends EditorPart {
-
- protected String initialQuery;
- protected String initialQueryType;
-
- // IoC
- private Session session;
-
- private TableViewer viewer;
- private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
- private GenericTableComparator comparator;
-
- protected abstract void createQueryForm(Composite parent);
-
- @Override
- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
- JcrQueryEditorInput editorInput = (JcrQueryEditorInput) input;
- initialQuery = editorInput.getQuery();
- initialQueryType = editorInput.getQueryType();
- setSite(site);
- setInput(editorInput);
- }
-
- @Override
- public final void createPartControl(final Composite parent) {
- parent.setLayout(new FillLayout());
-
- SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
- sashForm.setSashWidth(4);
- sashForm.setLayout(new FillLayout());
-
- Composite top = new Composite(sashForm, SWT.NONE);
- GridLayout gl = new GridLayout(1, false);
- top.setLayout(gl);
-
- createQueryForm(top);
-
- Composite bottom = new Composite(sashForm, SWT.NONE);
- bottom.setLayout(new GridLayout(1, false));
- sashForm.setWeights(getWeights());
-
- viewer = new TableViewer(bottom);
- viewer.getTable().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- viewer.getTable().setHeaderVisible(true);
- viewer.setContentProvider(getQueryResultContentProvider());
- viewer.setInput(getEditorSite());
-
- if (getComparator() != null) {
- comparator = getComparator();
- viewer.setComparator(comparator);
- }
- if (getTableDoubleClickListener() != null)
- viewer.addDoubleClickListener(getTableDoubleClickListener());
-
- }
-
- protected void executeQuery(String statement) {
- try {
- QueryResult qr = session.getWorkspace().getQueryManager()
- .createQuery(statement, initialQueryType).execute();
-
- // remove previous columns
- for (TableViewerColumn tvc : tableViewerColumns)
- tvc.getColumn().dispose();
-
- for (final String columnName : qr.getColumnNames()) {
- TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
- configureColumn(columnName, tvc);
- tvc.setLabelProvider(getLabelProvider(columnName));
- tableViewerColumns.add(tvc);
- }
-
- viewer.setInput(qr);
- } catch (RepositoryException e) {
- ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
- + statement, new Status(IStatus.ERROR,
- "org.argeo.eclipse.ui.jcr", e.getMessage()));
- // throw new ArgeoException("Cannot execute JCR query " + statement,
- // e);
- }
- }
-
- /**
- * To be overidden to adapt size of form and result frames.
- *
- * @return
- */
- protected int[] getWeights() {
- return new int[] { 30, 70 };
- }
-
- /**
- * To be overidden to implement a doubleclick Listener on one of the rows of
- * the table.
- *
- * @return
- */
- protected IDoubleClickListener getTableDoubleClickListener() {
- return null;
- }
-
- /**
- * To be overiden in order to implement a specific
- * QueryResultContentProvider
- */
- protected IStructuredContentProvider getQueryResultContentProvider() {
- return new QueryResultContentProvider();
- }
-
- /**
- * Enable specific implementation for columns
- */
- protected List<TableViewerColumn> getTableViewerColumns() {
- return tableViewerColumns;
- }
-
- /**
- * Enable specific implementation for columns
- */
- protected TableViewer getTableViewer() {
- return viewer;
- }
-
- /**
- * To be overridden in order to configure column label providers .
- */
- protected ColumnLabelProvider getLabelProvider(final String columnName) {
- return new ColumnLabelProvider() {
- public String getText(Object element) {
- Row row = (Row) element;
- try {
- return row.getValue(columnName).getString();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot display row " + row, e);
- }
- }
-
- public Image getImage(Object element) {
- return null;
- }
- };
- }
-
- /** To be overridden in order to configure the columns. */
- protected void configureColumn(String jcrColumnName,
- TableViewerColumn column) {
- column.getColumn().setWidth(50);
- column.getColumn().setText(jcrColumnName);
- }
-
- private class QueryResultContentProvider implements
- IStructuredContentProvider {
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public Object[] getElements(Object inputElement) {
- if (!(inputElement instanceof QueryResult))
- return new String[] {};
-
- try {
- QueryResult queryResult = (QueryResult) inputElement;
- List<Row> rows = new ArrayList<Row>();
- RowIterator rit = queryResult.getRows();
- while (rit.hasNext()) {
- rows.add(rit.nextRow());
- }
-
- // List<Node> elems = new ArrayList<Node>();
- // NodeIterator nit = queryResult.getNodes();
- // while (nit.hasNext()) {
- // elems.add(nit.nextNode());
- // }
- return rows.toArray();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot read query result", e);
- }
- }
-
- }
-
- /**
- * Might be used by children classes to sort columns.
- *
- * @param column
- * @param index
- * @return
- */
- protected SelectionAdapter getSelectionAdapter(final TableColumn column,
- final int index) {
-
- SelectionAdapter selectionAdapter = new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
-
- if (true)
- return;
- try {
-
- comparator.setColumn(index);
- int dir = viewer.getTable().getSortDirection();
- if (viewer.getTable().getSortColumn() == column) {
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- } else {
-
- dir = SWT.DOWN;
- }
- viewer.getTable().setSortDirection(dir);
- viewer.getTable().setSortColumn(column);
- viewer.refresh();
- } catch (Exception exc) {
- exc.printStackTrace();
- }
- }
- };
- return selectionAdapter;
- }
-
- /**
- * To be overriden to enable sorting.
- *
- * @author bsinou
- *
- */
- protected GenericTableComparator getComparator() {
- return null;
- }
-
- @Override
- public boolean isDirty() {
- return false;
- }
-
- @Override
- public void doSave(IProgressMonitor monitor) {
- // TODO save the query in JCR?
-
- }
-
- @Override
- public void doSaveAs() {
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- return false;
- }
-
- // IoC
- public void setSession(Session session) {
- this.session = session;
- }
-}
+++ /dev/null
-package org.argeo.eclipse.ui.jcr.editors;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-
-/** Executes any JCR query. */
-public class GenericJcrQueryEditor extends AbstractJcrQueryEditor {
- private Text queryField;
-
- @Override
- public void createQueryForm(Composite parent) {
- parent.setLayout(new GridLayout(1, false));
-
- queryField = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP);
- queryField.setText(initialQuery);
- queryField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
- Button execute = new Button(parent, SWT.PUSH);
- execute.setText("Execute");
-
- Listener executeListener = new Listener() {
- public void handleEvent(Event event) {
- executeQuery(queryField.getText());
- }
- };
-
- execute.addListener(SWT.Selection, executeListener);
- // queryField.addListener(SWT.DefaultSelection, executeListener);
- }
-
- @Override
- public void setFocus() {
- queryField.setFocus();
- }
-}
+++ /dev/null
-package org.argeo.eclipse.ui.jcr.editors;
-
-import javax.jcr.query.Query;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-public class JcrQueryEditorInput implements IEditorInput {
- private final String query;
- private final String queryType;
-
- public JcrQueryEditorInput(String query, String queryType) {
- this.query = query;
- if (queryType == null)
- this.queryType = Query.JCR_SQL2;
- else
- this.queryType = queryType;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return query;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return query;
- }
-
- public String getQuery() {
- return query;
- }
-
- public String getQueryType() {
- return queryType;
- }
-
-}
+++ /dev/null
-package org.argeo.eclipse.ui.jcr.views;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.jcr.Item;
-import javax.jcr.LoginException;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.RepositoryRegister;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.TreeNode;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.part.ViewPart;
-
-public class GenericJcrBrowser extends ViewPart {
- // private final static Log log =
- // LogFactory.getLog(GenericJcrBrowser.class);
-
- private TreeViewer nodesViewer;
- private TableViewer propertiesViewer;
-
- // private Session jcrSession;
- private RepositoryRegister repositoryRegister;
-
- private Comparator<Item> itemComparator = new Comparator<Item>() {
- public int compare(Item o1, Item o2) {
- try {
- return o1.getName().compareTo(o2.getName());
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot compare " + o1 + " and " + o2,
- e);
- }
- }
- };
-
- @Override
- public void createPartControl(Composite parent) {
- parent.setLayout(new FillLayout());
-
- SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
- sashForm.setSashWidth(4);
- sashForm.setLayout(new FillLayout());
-
- Composite top = new Composite(sashForm, SWT.NONE);
- GridLayout gl = new GridLayout(1, false);
- top.setLayout(gl);
-
- nodesViewer = new TreeViewer(top, SWT.MULTI | SWT.H_SCROLL
- | SWT.V_SCROLL);
- nodesViewer.getTree().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- nodesViewer.setContentProvider(new NodeContentProvider());
- nodesViewer.setLabelProvider(new NodeLabelProvider());
- nodesViewer
- .addSelectionChangedListener(new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- if (!event.getSelection().isEmpty()) {
- IStructuredSelection sel = (IStructuredSelection) event
- .getSelection();
- propertiesViewer.setInput(sel.getFirstElement());
- } else {
- propertiesViewer.setInput(getViewSite());
- }
- }
- });
- nodesViewer.addDoubleClickListener(new IDoubleClickListener() {
- public void doubleClick(DoubleClickEvent event) {
- Object obj = ((IStructuredSelection) event.getSelection())
- .getFirstElement();
- if (obj instanceof RepositoryNode) {
- ((RepositoryNode) obj).login();
- } else if (obj instanceof WorkspaceNode) {
- ((WorkspaceNode) obj).login();
- }
-
- }
- });
- nodesViewer.setInput(repositoryRegister);
-
- Composite bottom = new Composite(sashForm, SWT.NONE);
- bottom.setLayout(new GridLayout(1, false));
-
- propertiesViewer = new TableViewer(bottom);
- propertiesViewer.getTable().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- propertiesViewer.getTable().setHeaderVisible(true);
- propertiesViewer.setContentProvider(new PropertiesContentProvider());
- TableViewerColumn col = new TableViewerColumn(propertiesViewer,
- SWT.NONE);
- col.getColumn().setText("Name");
- col.getColumn().setWidth(200);
- col.setLabelProvider(new ColumnLabelProvider() {
- public String getText(Object element) {
- try {
- return ((Property) element).getName();
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception in label provider", e);
- }
- }
- });
- col = new TableViewerColumn(propertiesViewer, SWT.NONE);
- col.getColumn().setText("Value");
- col.getColumn().setWidth(400);
- col.setLabelProvider(new ColumnLabelProvider() {
- public String getText(Object element) {
- try {
- Property property = (Property) element;
- if (property.getType() == PropertyType.BINARY)
- return "<binary>";
- else if (property.isMultiple())
- return Arrays.asList(property.getValues()).toString();
- else
- return property.getValue().getString();
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception in label provider", e);
- }
- }
- });
- col = new TableViewerColumn(propertiesViewer, SWT.NONE);
- col.getColumn().setText("Type");
- col.getColumn().setWidth(200);
- col.setLabelProvider(new ColumnLabelProvider() {
- public String getText(Object element) {
- try {
- return PropertyType.nameFromValue(((Property) element)
- .getType());
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception in label provider", e);
- }
- }
- });
- propertiesViewer.setInput(getViewSite());
-
- sashForm.setWeights(getWeights());
-
- }
-
- @Override
- public void setFocus() {
- nodesViewer.getTree().setFocus();
- }
-
- /**
- * To be overidden to adapt size of form and result frames.
- *
- * @return
- */
- protected int[] getWeights() {
- return new int[] { 70, 30 };
- }
-
- public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
- this.repositoryRegister = repositoryRegister;
- }
-
- /*
- * NODES
- */
- protected Object[] childrenNodes(Node parentNode) {
- try {
- List<Node> children = new ArrayList<Node>();
- NodeIterator nit = parentNode.getNodes();
- while (nit.hasNext()) {
- Node node = nit.nextNode();
- children.add(node);
- }
- Node[] arr = children.toArray(new Node[children.size()]);
- Arrays.sort(arr, itemComparator);
- return arr;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot list children of " + parentNode, e);
- }
- }
-
- private class NodeContentProvider implements ITreeContentProvider {
-
- public Object[] getElements(Object inputElement) {
- return getChildren(inputElement);
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Node) {
- return childrenNodes((Node) parentElement);
- } else if (parentElement instanceof RepositoryNode) {
- return ((RepositoryNode) parentElement).getChildren();
- } else if (parentElement instanceof WorkspaceNode) {
- Session session = ((WorkspaceNode) parentElement).getSession();
- if (session == null)
- return new Object[0];
-
- try {
- return childrenNodes(session.getRootNode());
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot retrieve root node of "
- + session, e);
- }
- } else if (parentElement instanceof RepositoryRegister) {
- RepositoryRegister repositoryRegister = (RepositoryRegister) parentElement;
- List<RepositoryNode> nodes = new ArrayList<RepositoryNode>();
- Map<String, Repository> repositories = repositoryRegister
- .getRepositories();
- for (String name : repositories.keySet()) {
- nodes.add(new RepositoryNode(name, repositories.get(name)));
- }
- return nodes.toArray();
- } else {
- return new Object[0];
- }
- }
-
- public Object getParent(Object element) {
- try {
- if (element instanceof Node) {
- return ((Node) element).getParent();
- }
- return null;
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot retrieve parent of " + element, e);
- }
- }
-
- public boolean hasChildren(Object element) {
- try {
- if (element instanceof Node) {
- return ((Node) element).hasNodes();
- } else if (element instanceof RepositoryNode) {
- return ((RepositoryNode) element).hasChildren();
- } else if (element instanceof WorkspaceNode) {
- return ((WorkspaceNode) element).getSession() != null;
- }
- return false;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot check children of " + element,
- e);
- }
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- }
-
- class NodeLabelProvider extends LabelProvider {
-
- public String getText(Object element) {
- try {
- if (element instanceof Node) {
- Node node = (Node) element;
- String label = node.getName();
- // try {
- // Item primaryItem = node.getPrimaryItem();
- // label = primaryItem instanceof Property ? ((Property)
- // primaryItem)
- // .getValue().getString()
- // + " ("
- // + node.getName()
- // + ")" : node.getName();
- // } catch (RepositoryException e) {
- // label = node.getName();
- // }
- StringBuffer mixins = new StringBuffer("");
- for (NodeType type : node.getMixinNodeTypes())
- mixins.append(' ').append(type.getName());
-
- return label + " [" + node.getPrimaryNodeType().getName()
- + mixins + "]";
- }
- return element.toString();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot get text for of " + element, e);
- }
- }
-
- }
-
- /*
- * PROPERTIES
- */
- private class PropertiesContentProvider implements
- IStructuredContentProvider {
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public Object[] getElements(Object inputElement) {
- try {
- if (inputElement instanceof Node) {
- Set<Property> props = new TreeSet<Property>(itemComparator);
- PropertyIterator pit = ((Node) inputElement)
- .getProperties();
- while (pit.hasNext())
- props.add(pit.nextProperty());
- return props.toArray();
- }
- return new Object[] {};
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot get element for "
- + inputElement, e);
- }
- }
-
- }
-
- private class RepositoryNode extends TreeParent {
- private final String name;
- private final Repository repository;
- private Session defaultSession = null;
-
- public RepositoryNode(String name, Repository repository) {
- super(name);
- this.name = name;
- this.repository = repository;
- }
-
- public Repository getRepository() {
- return repository;
- }
-
- public Session getDefaultSession() {
- return defaultSession;
- }
-
- public void login() {
- try {
- defaultSession = repository.login();
- String[] wkpNames = defaultSession.getWorkspace()
- .getAccessibleWorkspaceNames();
- for (String wkpName : wkpNames) {
- if (wkpName.equals(defaultSession.getWorkspace().getName()))
- addChild(new WorkspaceNode(repository, wkpName,
- defaultSession));
- else
- addChild(new WorkspaceNode(repository, wkpName));
- }
- nodesViewer.refresh(this);
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot connect to repository " + name, e);
- }
- }
- }
-
- private class WorkspaceNode extends TreeParent {
- private final String name;
- private final Repository repository;
- private Session session = null;
-
- public WorkspaceNode(Repository repository, String name) {
- this(repository, name, null);
- }
-
- public WorkspaceNode(Repository repository, String name, Session session) {
- super(name);
- this.name = name;
- this.repository = repository;
- this.session = session;
- }
-
- public Session getSession() {
- return session;
- }
-
- public void login() {
- try {
- if (session != null)
- session.logout();
-
- session = repository.login(name);
- nodesViewer.refresh(this);
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot connect to repository " + name, e);
- }
- }
-
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.argeo.eclipse.ui</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
+++ /dev/null
-#Thu Jul 29 10:54:11 CEST 2010
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+++ /dev/null
-#Thu Jul 29 11:00:39 CEST 2010
-eclipse.preferences.version=1
-resolve.requirebundle=false
+++ /dev/null
-source.. = src/main/java/
-output.. = target/classes/
-bin.includes = META-INF/,\
- .
+++ /dev/null
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.argeo.commons.eclipse</groupId>
- <version>0.2.3-SNAPSHOT</version>
- <artifactId>plugins</artifactId>
- <relativePath>..</relativePath>
- </parent>
- <artifactId>org.argeo.eclipse.ui</artifactId>
- <name>Commons Eclipse UI</name>
- <packaging>jar</packaging>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${version.maven-bundle-plugin}</version>
- <configuration>
- <instructions>
- <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
- <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
- <Require-Bundle>org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime</Require-Bundle>
- <Import-Package>
- org.springframework.beans.factory,
- org.springframework.core.io.support,
- !org.eclipse.core.runtime,
- !org.eclipse.core.commands,
- !org.eclipse.ui.plugin,
- *
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
-
- <!-- Argeo Eclipse distribution (common dependencies for both RAP and RCP) -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.common</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- JCR -->
- <dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.jcr</artifactId>
- </dependency>
-
- <!-- RCP only dependency, needed at compile time -->
- <dependency>
- <groupId>org.argeo.commons.eclipse</groupId>
- <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- Commons -->
- <dependency>
- <groupId>org.argeo.commons.basic</groupId>
- <artifactId>org.argeo.basic.nodeps</artifactId>
- <version>0.2.3-SNAPSHOT</version>
- </dependency>
-
- <!-- Spring -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.context</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>org.springframework.osgi.extender</artifactId>
- </dependency>
-
- <!-- Others -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
- </dependency>
-
- </dependencies>
-</project>
+++ /dev/null
-/*\r
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.argeo.eclipse.spring;\r
-\r
-import static java.text.MessageFormat.format;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.eclipse.core.runtime.Platform;\r
-import org.osgi.framework.Bundle;\r
-import org.osgi.framework.BundleContext;\r
-import org.osgi.framework.BundleException;\r
-import org.osgi.framework.FrameworkUtil;\r
-import org.osgi.framework.InvalidSyntaxException;\r
-import org.osgi.util.tracker.ServiceTracker;\r
-import org.springframework.context.ApplicationContext;\r
-\r
-/**\r
- * @author Heiko Seeberger\r
- * @author Mathieu Baudier\r
- */\r
-class ApplicationContextTracker {\r
- private final static Log log = LogFactory\r
- .getLog(ApplicationContextTracker.class);\r
-\r
- private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$\r
- + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$\r
-\r
- private ServiceTracker applicationContextServiceTracker;\r
-\r
- /**\r
- * @param contributorBundle\r
- * OSGi bundle for which the Spring application context is to be\r
- * tracked. Must not be null!\r
- * @param factoryBundleContext\r
- * BundleContext object which can be used to track services\r
- * @throws IllegalArgumentException\r
- * if the given bundle is null.\r
- */\r
- public ApplicationContextTracker(final Bundle contributorBundle,\r
- final BundleContext factoryBundleContext) {\r
- final String filter = format(FILTER,\r
- contributorBundle.getSymbolicName());\r
- try {\r
- applicationContextServiceTracker = new ServiceTracker(\r
- factoryBundleContext, FrameworkUtil.createFilter(filter),\r
- null);\r
- applicationContextServiceTracker.open();\r
- } catch (final InvalidSyntaxException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- public void close() {\r
- if (applicationContextServiceTracker != null) {\r
- applicationContextServiceTracker.close();\r
- }\r
- }\r
-\r
- public ApplicationContext getApplicationContext() {\r
- ApplicationContext applicationContext = null;\r
- if (applicationContextServiceTracker != null) {\r
- try {\r
- applicationContext = (ApplicationContext) applicationContextServiceTracker\r
- .waitForService(5000);\r
- } catch (InterruptedException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- return applicationContext;\r
- }\r
-\r
- @Override\r
- protected void finalize() throws Throwable {\r
- close();\r
- super.finalize();\r
- }\r
-\r
- static ApplicationContext getApplicationContext(String bundleSymbolicName) {\r
- Bundle contributorBundle = Platform.getBundle(bundleSymbolicName);\r
- return getApplicationContext(contributorBundle);\r
- }\r
-\r
- static ApplicationContext getApplicationContext(Bundle contributorBundle) {\r
- if (log.isTraceEnabled())\r
- log.trace("Get application context for bundle " + contributorBundle);\r
-\r
- if (contributorBundle.getState() != Bundle.ACTIVE\r
- && contributorBundle.getState() != Bundle.STARTING) {\r
- try {\r
- log.info("Starting bundle: "\r
- + contributorBundle.getSymbolicName());\r
- contributorBundle.start();\r
- } catch (BundleException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
- contributorBundle, contributorBundle.getBundleContext());\r
- ApplicationContext applicationContext = null;\r
- try {\r
- applicationContext = applicationContextTracker\r
- .getApplicationContext();\r
- } finally {\r
- applicationContextTracker.close();\r
- }\r
- return applicationContext;\r
- }\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.argeo.eclipse.spring;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.commands.IHandlerListener;
-import org.springframework.context.ApplicationContext;
-
-public class SpringCommandHandler implements IHandler {
- private final static Log log = LogFactory
- .getLog(SpringCommandHandler.class);
-
- public void addHandlerListener(IHandlerListener handlerListener) {
- }
-
- public void dispose() {
- }
-
- public Object execute(ExecutionEvent event) throws ExecutionException {
- String commandId = event.getCommand().getId();
- String bundleSymbolicName = commandId.substring(0,
- commandId.lastIndexOf('.'));
- try {
- if (log.isTraceEnabled())
- log.trace("Execute " + event + " via spring command handler "
- + this);
- // TODO: make it more flexible and robust
- ApplicationContext applicationContext = ApplicationContextTracker
- .getApplicationContext(bundleSymbolicName);
-
- // retrieve the command via its id
- String beanName = event.getCommand().getId();
- if (!applicationContext.containsBean(beanName))
- throw new ExecutionException("No bean found with name "
- + beanName + " in bundle " + bundleSymbolicName);
- Object bean = applicationContext.getBean(beanName);
-
- if (!(bean instanceof IHandler))
- throw new ExecutionException("Bean with name " + beanName
- + " and class " + bean.getClass()
- + " does not implement the IHandler interface.");
-
- IHandler handler = (IHandler) bean;
- return handler.execute(event);
- } catch (Exception e) {
- // TODO: use eclipse error management
-// log.error(e);
- throw new ExecutionException("Cannot execute Spring command "
- + commandId + " in bundle " + bundleSymbolicName, e);
- }
- }
-
- public boolean isEnabled() {
- return true;
- }
-
- public boolean isHandled() {
- return true;
- }
-
- public void removeHandlerListener(IHandlerListener handlerListener) {
- }
-
-}
+++ /dev/null
-/*\r
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-package org.argeo.eclipse.spring;\r
-\r
-import org.argeo.ArgeoException;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IConfigurationElement;\r
-import org.eclipse.core.runtime.IExecutableExtension;\r
-import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
-import org.eclipse.core.runtime.IExtension;\r
-import org.springframework.context.ApplicationContext;\r
-\r
-/**\r
- * The Spring Extension Factory builds a bridge between the Eclipse Extension\r
- * Registry and the Spring Framework (especially Spring Dynamic Modules).\r
- * \r
- * It allows you to define your extension as a spring bean within the spring\r
- * application context of your bundle. If you would like to use this bean as an\r
- * instance of an extension (an Eclipse RCP view, for example) you define the\r
- * extension with this spring extension factory as the class to be created.\r
- * \r
- * To let the spring extension factory pick the right bean from your application\r
- * context you need to set the bean id to the same value as the id of the view\r
- * within the view definition, for example. This is important if your extension\r
- * definition contains more than one element, where each element has its own id.\r
- * \r
- * If the extension definition elements themselves have no id attribute the\r
- * spring extension factory uses the id of the extension itself to identify the\r
- * bean.\r
- * \r
- * original code from: <a href=\r
- * "http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
- * >Blog entry</a>\r
- * \r
- * @author Martin Lippert\r
- * @author mbaudier\r
- */\r
-public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
- IExecutableExtension {\r
-\r
- private Object bean;\r
-\r
- public Object create() throws CoreException {\r
- if (bean == null)\r
- throw new ArgeoException("No underlying bean for extension");\r
- return bean;\r
- }\r
-\r
- public void setInitializationData(IConfigurationElement config,\r
- String propertyName, Object data) throws CoreException {\r
- String beanName = getBeanName(data, config);\r
- if (beanName == null)\r
- throw new ArgeoException("Cannot find bean name for extension "\r
- + config);\r
-\r
- String bundleSymbolicName = config.getContributor().getName();\r
- ApplicationContext appContext = ApplicationContextTracker\r
- .getApplicationContext(bundleSymbolicName);\r
- if (appContext == null)\r
- throw new ArgeoException(\r
- "Cannot find application context for bundle "\r
- + bundleSymbolicName);\r
-\r
- this.bean = appContext.getBean(beanName);\r
- if (this.bean instanceof IExecutableExtension) {\r
- ((IExecutableExtension) this.bean).setInitializationData(config,\r
- propertyName, data);\r
- }\r
- }\r
-\r
- private String getBeanName(Object data, IConfigurationElement config) {\r
-\r
- // try the specific bean id the extension defines\r
- if (data != null && data.toString().length() > 0) {\r
- return data.toString();\r
- }\r
-\r
- // try the id of the config element\r
- if (config.getAttribute("id") != null) {\r
- return config.getAttribute("id");\r
- }\r
-\r
- // try the id of the extension element itself\r
- if (config.getParent() != null\r
- && config.getParent() instanceof IExtension) {\r
- IExtension extensionDefinition = (IExtension) config.getParent();\r
- return extensionDefinition.getSimpleIdentifier();\r
- }\r
-\r
- return null;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.argeo.eclipse.ui;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class ArgeoUiPlugin extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
-
- private final static String SPRING_OSGI_EXTENDER = "org.springframework.osgi.extender";
-
- // The shared instance
- private static ArgeoUiPlugin plugin;
-
- private BundleContext bundleContext;
-
- /**
- * The constructor
- */
- public ArgeoUiPlugin() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- bundleContext = context;
-
- // Make sure that the Spring OSGi extender is started
- Bundle osgiExtBundle = Platform.getBundle(SPRING_OSGI_EXTENDER);
- if (osgiExtBundle != null)
- osgiExtBundle.start();
- else
- throw new Exception("Spring OSGi Extender not found");
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
- * )
- */
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static ArgeoUiPlugin getDefault() {
- return plugin;
- }
-
- public BundleContext getBundleContext() {
- return bundleContext;
- }
-
-}
+++ /dev/null
-package org.argeo.eclipse.ui;
-
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-
-public abstract class GenericTableComparator extends ViewerComparator {
-
- protected int propertyIndex;
- public static final int ASCENDING = 0, DESCENDING = 1;
- protected int direction = DESCENDING;
-
- /**
- * Creates an instance of a sorter for TableViewer.
- *
- * @param defaultColumn
- * the default sorter column
- */
-
- public GenericTableComparator(int defaultColumnIndex, int direction) {
- propertyIndex = defaultColumnIndex;
- this.direction = direction;
- }
-
- public void setColumn(int column) {
- if (column == this.propertyIndex) {
- // Same column as last sort; toggle the direction
- direction = 1 - direction;
- } else {
- // New column; do a descending sort
- this.propertyIndex = column;
- direction = DESCENDING;
- }
- }
-
- /**
- * Must be Overriden in each view.
- */
- public abstract int compare(Viewer viewer, Object e1, Object e2);
-}
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.argeo.eclipse.ui;
-
-public class TreeObject implements Comparable<TreeObject> {
- private String name;
- private TreeParent parent;
-
- public TreeObject(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setParent(TreeParent parent) {
- this.parent = parent;
- }
-
- public TreeParent getParent() {
- return parent;
- }
-
- public String toString() {
- return getName();
- }
-
- public int compareTo(TreeObject o) {
- return name.compareTo(o.name);
- }
-
- @Override
- public int hashCode() {
- return name.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- return name.equals(obj.toString());
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.argeo.eclipse.ui;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class TreeParent extends TreeObject {
- private List<TreeObject> children;
-
- private boolean loaded;
-
- public TreeParent(String name) {
- super(name);
- children = new ArrayList<TreeObject>();
- loaded = false;
- }
-
- public synchronized void addChild(TreeObject child) {
- loaded = true;
- children.add(child);
- child.setParent(this);
- }
-
- public synchronized void removeChild(TreeObject child) {
- children.remove(child);
- child.setParent(null);
- }
-
- public synchronized void clearChildren() {
- loaded = false;
- children.clear();
- }
-
- public synchronized TreeObject[] getChildren() {
- return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
- }
-
- public synchronized boolean hasChildren() {
- return children.size() > 0;
- }
-
- public TreeObject getChildByName(String name) {
- for (TreeObject child : children) {
- if (child.getName().equals(name))
- return child;
- }
- return null;
- }
-
- public synchronized Boolean isLoaded() {
- return loaded;
- }
-}
<name>Commons Eclipse plugins</name>
<packaging>pom</packaging>
<modules>
- <module>org.argeo.eclipse.ui</module>
- <module>org.argeo.eclipse.ui.jcr</module>
+ <module>org.argeo.eclipse.ui.jcr.explorer</module>
</modules>
<build>
<resources>
</resource>
</resources>
<plugins>
- <plugin>
- <artifactId>maven-clean-plugin</artifactId>
- <configuration>
- <filesets>
- <fileset>
- <directory>META-INF</directory>
- <includes>
- <include>MANIFEST.MF</include>
- </includes>
- </fileset>
- </filesets>
- </configuration>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifestFile>META-INF/MANIFEST.MF</manifestFile>
- </archive>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>${version.maven-bundle-plugin}</version>
- <extensions>true</extensions>
- <configuration>
- <manifestLocation>META-INF</manifestLocation>
- </configuration>
- <executions>
- <execution>
- <id>bundle-manifest</id>
- <phase>process-classes</phase>
- <goals>
- <goal>manifest</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
</project>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.eclipse.ui.jcr</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Sat Jan 22 14:25:47 CET 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
--- /dev/null
+#Sat Jan 22 14:25:47 CET 2011
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
--- /dev/null
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <version>0.2.3-SNAPSHOT</version>
+ <artifactId>runtime</artifactId>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>org.argeo.eclipse.ui.jcr</artifactId>
+ <name>Commons Eclipse UI JCR</name>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${version.maven-bundle-plugin}</version>
+ <configuration>
+ <instructions>
+ <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+ <Import-Package>
+ org.eclipse.swt,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+
+ <!-- Argeo Eclipse distribution (common dependencies for both RAP and RCP) -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.common</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.ui</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <!-- JCR -->
+ <dependency>
+ <groupId>org.argeo.dep.osgi</groupId>
+ <artifactId>org.argeo.dep.osgi.jcr</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.argeo.commons.server</groupId>
+ <artifactId>org.argeo.server.jcr</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <!-- RCP only dependency, needed at compile time -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Argeo Commons -->
+ <dependency>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>org.argeo.basic.nodeps</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
+ </dependencies>
+</project>
--- /dev/null
+package org.argeo.eclipse.ui.jcr.commands;
+
+import org.argeo.eclipse.ui.jcr.editors.JcrQueryEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Open a JCR query editor. */
+public class OpenGenericJcrQueryEditor extends AbstractHandler {
+ private String editorId;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ JcrQueryEditorInput editorInput = new JcrQueryEditorInput("", null);
+ IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(
+ event).getActivePage();
+ activePage.openEditor(editorInput, editorId);
+ } catch (Exception e) {
+ throw new ExecutionException("Cannot open editor", e);
+ }
+ return null;
+ }
+
+ public void setEditorId(String editorId) {
+ this.editorId = editorId;
+ }
+
+}
--- /dev/null
+package org.argeo.eclipse.ui.jcr.editors;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.GenericTableComparator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+
+/** Executes any JCR query. */
+public abstract class AbstractJcrQueryEditor extends EditorPart {
+
+ protected String initialQuery;
+ protected String initialQueryType;
+
+ // IoC
+ private Session session;
+
+ private TableViewer viewer;
+ private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
+ private GenericTableComparator comparator;
+
+ protected abstract void createQueryForm(Composite parent);
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ JcrQueryEditorInput editorInput = (JcrQueryEditorInput) input;
+ initialQuery = editorInput.getQuery();
+ initialQueryType = editorInput.getQueryType();
+ setSite(site);
+ setInput(editorInput);
+ }
+
+ @Override
+ public final void createPartControl(final Composite parent) {
+ parent.setLayout(new FillLayout());
+
+ SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
+ sashForm.setSashWidth(4);
+ sashForm.setLayout(new FillLayout());
+
+ Composite top = new Composite(sashForm, SWT.NONE);
+ GridLayout gl = new GridLayout(1, false);
+ top.setLayout(gl);
+
+ createQueryForm(top);
+
+ Composite bottom = new Composite(sashForm, SWT.NONE);
+ bottom.setLayout(new GridLayout(1, false));
+ sashForm.setWeights(getWeights());
+
+ viewer = new TableViewer(bottom);
+ viewer.getTable().setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.getTable().setHeaderVisible(true);
+ viewer.setContentProvider(getQueryResultContentProvider());
+ viewer.setInput(getEditorSite());
+
+ if (getComparator() != null) {
+ comparator = getComparator();
+ viewer.setComparator(comparator);
+ }
+ if (getTableDoubleClickListener() != null)
+ viewer.addDoubleClickListener(getTableDoubleClickListener());
+
+ }
+
+ protected void executeQuery(String statement) {
+ try {
+ QueryResult qr = session.getWorkspace().getQueryManager()
+ .createQuery(statement, initialQueryType).execute();
+
+ // remove previous columns
+ for (TableViewerColumn tvc : tableViewerColumns)
+ tvc.getColumn().dispose();
+
+ for (final String columnName : qr.getColumnNames()) {
+ TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
+ configureColumn(columnName, tvc);
+ tvc.setLabelProvider(getLabelProvider(columnName));
+ tableViewerColumns.add(tvc);
+ }
+
+ viewer.setInput(qr);
+ } catch (RepositoryException e) {
+ ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
+ + statement, new Status(IStatus.ERROR,
+ "org.argeo.eclipse.ui.jcr", e.getMessage()));
+ // throw new ArgeoException("Cannot execute JCR query " + statement,
+ // e);
+ }
+ }
+
+ /**
+ * To be overidden to adapt size of form and result frames.
+ *
+ * @return
+ */
+ protected int[] getWeights() {
+ return new int[] { 30, 70 };
+ }
+
+ /**
+ * To be overidden to implement a doubleclick Listener on one of the rows of
+ * the table.
+ *
+ * @return
+ */
+ protected IDoubleClickListener getTableDoubleClickListener() {
+ return null;
+ }
+
+ /**
+ * To be overiden in order to implement a specific
+ * QueryResultContentProvider
+ */
+ protected IStructuredContentProvider getQueryResultContentProvider() {
+ return new QueryResultContentProvider();
+ }
+
+ /**
+ * Enable specific implementation for columns
+ */
+ protected List<TableViewerColumn> getTableViewerColumns() {
+ return tableViewerColumns;
+ }
+
+ /**
+ * Enable specific implementation for columns
+ */
+ protected TableViewer getTableViewer() {
+ return viewer;
+ }
+
+ /**
+ * To be overridden in order to configure column label providers .
+ */
+ protected ColumnLabelProvider getLabelProvider(final String columnName) {
+ return new ColumnLabelProvider() {
+ public String getText(Object element) {
+ Row row = (Row) element;
+ try {
+ return row.getValue(columnName).getString();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot display row " + row, e);
+ }
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+ };
+ }
+
+ /** To be overridden in order to configure the columns. */
+ protected void configureColumn(String jcrColumnName,
+ TableViewerColumn column) {
+ column.getColumn().setWidth(50);
+ column.getColumn().setText(jcrColumnName);
+ }
+
+ private class QueryResultContentProvider implements
+ IStructuredContentProvider {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (!(inputElement instanceof QueryResult))
+ return new String[] {};
+
+ try {
+ QueryResult queryResult = (QueryResult) inputElement;
+ List<Row> rows = new ArrayList<Row>();
+ RowIterator rit = queryResult.getRows();
+ while (rit.hasNext()) {
+ rows.add(rit.nextRow());
+ }
+
+ // List<Node> elems = new ArrayList<Node>();
+ // NodeIterator nit = queryResult.getNodes();
+ // while (nit.hasNext()) {
+ // elems.add(nit.nextNode());
+ // }
+ return rows.toArray();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot read query result", e);
+ }
+ }
+
+ }
+
+ /**
+ * Might be used by children classes to sort columns.
+ *
+ * @param column
+ * @param index
+ * @return
+ */
+ protected SelectionAdapter getSelectionAdapter(final TableColumn column,
+ final int index) {
+
+ SelectionAdapter selectionAdapter = new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ if (true)
+ return;
+ try {
+
+ comparator.setColumn(index);
+ int dir = viewer.getTable().getSortDirection();
+ if (viewer.getTable().getSortColumn() == column) {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ } else {
+
+ dir = SWT.DOWN;
+ }
+ viewer.getTable().setSortDirection(dir);
+ viewer.getTable().setSortColumn(column);
+ viewer.refresh();
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ }
+ }
+ };
+ return selectionAdapter;
+ }
+
+ /**
+ * To be overriden to enable sorting.
+ *
+ * @author bsinou
+ *
+ */
+ protected GenericTableComparator getComparator() {
+ return null;
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ // TODO save the query in JCR?
+
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ // IoC
+ public void setSession(Session session) {
+ this.session = session;
+ }
+}
--- /dev/null
+package org.argeo.eclipse.ui.jcr.editors;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/** Executes any JCR query. */
+public class GenericJcrQueryEditor extends AbstractJcrQueryEditor {
+ private Text queryField;
+
+ @Override
+ public void createQueryForm(Composite parent) {
+ parent.setLayout(new GridLayout(1, false));
+
+ queryField = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.WRAP);
+ queryField.setText(initialQuery);
+ queryField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Button execute = new Button(parent, SWT.PUSH);
+ execute.setText("Execute");
+
+ Listener executeListener = new Listener() {
+ public void handleEvent(Event event) {
+ executeQuery(queryField.getText());
+ }
+ };
+
+ execute.addListener(SWT.Selection, executeListener);
+ // queryField.addListener(SWT.DefaultSelection, executeListener);
+ }
+
+ @Override
+ public void setFocus() {
+ queryField.setFocus();
+ }
+}
--- /dev/null
+package org.argeo.eclipse.ui.jcr.editors;
+
+import javax.jcr.query.Query;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+public class JcrQueryEditorInput implements IEditorInput {
+ private final String query;
+ private final String queryType;
+
+ public JcrQueryEditorInput(String query, String queryType) {
+ this.query = query;
+ if (queryType == null)
+ this.queryType = Query.JCR_SQL2;
+ else
+ this.queryType = queryType;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return query;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return query;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public String getQueryType() {
+ return queryType;
+ }
+
+}
--- /dev/null
+package org.argeo.eclipse.ui.jcr.views;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.jcr.Item;
+import javax.jcr.LoginException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.RepositoryRegister;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.TreeNode;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+public class GenericJcrBrowser extends ViewPart {
+ // private final static Log log =
+ // LogFactory.getLog(GenericJcrBrowser.class);
+
+ private TreeViewer nodesViewer;
+ private TableViewer propertiesViewer;
+
+ // private Session jcrSession;
+ private RepositoryRegister repositoryRegister;
+
+ private Comparator<Item> itemComparator = new Comparator<Item>() {
+ public int compare(Item o1, Item o2) {
+ try {
+ return o1.getName().compareTo(o2.getName());
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot compare " + o1 + " and " + o2,
+ e);
+ }
+ }
+ };
+
+ @Override
+ public void createPartControl(Composite parent) {
+ parent.setLayout(new FillLayout());
+
+ SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
+ sashForm.setSashWidth(4);
+ sashForm.setLayout(new FillLayout());
+
+ Composite top = new Composite(sashForm, SWT.NONE);
+ GridLayout gl = new GridLayout(1, false);
+ top.setLayout(gl);
+
+ nodesViewer = new TreeViewer(top, SWT.MULTI | SWT.H_SCROLL
+ | SWT.V_SCROLL);
+ nodesViewer.getTree().setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, true, true));
+ nodesViewer.setContentProvider(new NodeContentProvider());
+ nodesViewer.setLabelProvider(new NodeLabelProvider());
+ nodesViewer
+ .addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (!event.getSelection().isEmpty()) {
+ IStructuredSelection sel = (IStructuredSelection) event
+ .getSelection();
+ propertiesViewer.setInput(sel.getFirstElement());
+ } else {
+ propertiesViewer.setInput(getViewSite());
+ }
+ }
+ });
+ nodesViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ Object obj = ((IStructuredSelection) event.getSelection())
+ .getFirstElement();
+ if (obj instanceof RepositoryNode) {
+ ((RepositoryNode) obj).login();
+ } else if (obj instanceof WorkspaceNode) {
+ ((WorkspaceNode) obj).login();
+ }
+
+ }
+ });
+ nodesViewer.setInput(repositoryRegister);
+
+ Composite bottom = new Composite(sashForm, SWT.NONE);
+ bottom.setLayout(new GridLayout(1, false));
+
+ propertiesViewer = new TableViewer(bottom);
+ propertiesViewer.getTable().setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, true, true));
+ propertiesViewer.getTable().setHeaderVisible(true);
+ propertiesViewer.setContentProvider(new PropertiesContentProvider());
+ TableViewerColumn col = new TableViewerColumn(propertiesViewer,
+ SWT.NONE);
+ col.getColumn().setText("Name");
+ col.getColumn().setWidth(200);
+ col.setLabelProvider(new ColumnLabelProvider() {
+ public String getText(Object element) {
+ try {
+ return ((Property) element).getName();
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception in label provider", e);
+ }
+ }
+ });
+ col = new TableViewerColumn(propertiesViewer, SWT.NONE);
+ col.getColumn().setText("Value");
+ col.getColumn().setWidth(400);
+ col.setLabelProvider(new ColumnLabelProvider() {
+ public String getText(Object element) {
+ try {
+ Property property = (Property) element;
+ if (property.getType() == PropertyType.BINARY)
+ return "<binary>";
+ else if (property.isMultiple())
+ return Arrays.asList(property.getValues()).toString();
+ else
+ return property.getValue().getString();
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception in label provider", e);
+ }
+ }
+ });
+ col = new TableViewerColumn(propertiesViewer, SWT.NONE);
+ col.getColumn().setText("Type");
+ col.getColumn().setWidth(200);
+ col.setLabelProvider(new ColumnLabelProvider() {
+ public String getText(Object element) {
+ try {
+ return PropertyType.nameFromValue(((Property) element)
+ .getType());
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception in label provider", e);
+ }
+ }
+ });
+ propertiesViewer.setInput(getViewSite());
+
+ sashForm.setWeights(getWeights());
+
+ }
+
+ @Override
+ public void setFocus() {
+ nodesViewer.getTree().setFocus();
+ }
+
+ /**
+ * To be overidden to adapt size of form and result frames.
+ *
+ * @return
+ */
+ protected int[] getWeights() {
+ return new int[] { 70, 30 };
+ }
+
+ public void setRepositoryRegister(RepositoryRegister repositoryRegister) {
+ this.repositoryRegister = repositoryRegister;
+ }
+
+ /*
+ * NODES
+ */
+ protected Object[] childrenNodes(Node parentNode) {
+ try {
+ List<Node> children = new ArrayList<Node>();
+ NodeIterator nit = parentNode.getNodes();
+ while (nit.hasNext()) {
+ Node node = nit.nextNode();
+ children.add(node);
+ }
+ Node[] arr = children.toArray(new Node[children.size()]);
+ Arrays.sort(arr, itemComparator);
+ return arr;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot list children of " + parentNode, e);
+ }
+ }
+
+ private class NodeContentProvider implements ITreeContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof Node) {
+ return childrenNodes((Node) parentElement);
+ } else if (parentElement instanceof RepositoryNode) {
+ return ((RepositoryNode) parentElement).getChildren();
+ } else if (parentElement instanceof WorkspaceNode) {
+ Session session = ((WorkspaceNode) parentElement).getSession();
+ if (session == null)
+ return new Object[0];
+
+ try {
+ return childrenNodes(session.getRootNode());
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot retrieve root node of "
+ + session, e);
+ }
+ } else if (parentElement instanceof RepositoryRegister) {
+ RepositoryRegister repositoryRegister = (RepositoryRegister) parentElement;
+ List<RepositoryNode> nodes = new ArrayList<RepositoryNode>();
+ Map<String, Repository> repositories = repositoryRegister
+ .getRepositories();
+ for (String name : repositories.keySet()) {
+ nodes.add(new RepositoryNode(name, repositories.get(name)));
+ }
+ return nodes.toArray();
+ } else {
+ return new Object[0];
+ }
+ }
+
+ public Object getParent(Object element) {
+ try {
+ if (element instanceof Node) {
+ return ((Node) element).getParent();
+ }
+ return null;
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Cannot retrieve parent of " + element, e);
+ }
+ }
+
+ public boolean hasChildren(Object element) {
+ try {
+ if (element instanceof Node) {
+ return ((Node) element).hasNodes();
+ } else if (element instanceof RepositoryNode) {
+ return ((RepositoryNode) element).hasChildren();
+ } else if (element instanceof WorkspaceNode) {
+ return ((WorkspaceNode) element).getSession() != null;
+ }
+ return false;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot check children of " + element,
+ e);
+ }
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ }
+
+ class NodeLabelProvider extends LabelProvider {
+
+ public String getText(Object element) {
+ try {
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ String label = node.getName();
+ // try {
+ // Item primaryItem = node.getPrimaryItem();
+ // label = primaryItem instanceof Property ? ((Property)
+ // primaryItem)
+ // .getValue().getString()
+ // + " ("
+ // + node.getName()
+ // + ")" : node.getName();
+ // } catch (RepositoryException e) {
+ // label = node.getName();
+ // }
+ StringBuffer mixins = new StringBuffer("");
+ for (NodeType type : node.getMixinNodeTypes())
+ mixins.append(' ').append(type.getName());
+
+ return label + " [" + node.getPrimaryNodeType().getName()
+ + mixins + "]";
+ }
+ return element.toString();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot get text for of " + element, e);
+ }
+ }
+
+ }
+
+ /*
+ * PROPERTIES
+ */
+ private class PropertiesContentProvider implements
+ IStructuredContentProvider {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ try {
+ if (inputElement instanceof Node) {
+ Set<Property> props = new TreeSet<Property>(itemComparator);
+ PropertyIterator pit = ((Node) inputElement)
+ .getProperties();
+ while (pit.hasNext())
+ props.add(pit.nextProperty());
+ return props.toArray();
+ }
+ return new Object[] {};
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot get element for "
+ + inputElement, e);
+ }
+ }
+
+ }
+
+ private class RepositoryNode extends TreeParent {
+ private final String name;
+ private final Repository repository;
+ private Session defaultSession = null;
+
+ public RepositoryNode(String name, Repository repository) {
+ super(name);
+ this.name = name;
+ this.repository = repository;
+ }
+
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public Session getDefaultSession() {
+ return defaultSession;
+ }
+
+ public void login() {
+ try {
+ defaultSession = repository.login();
+ String[] wkpNames = defaultSession.getWorkspace()
+ .getAccessibleWorkspaceNames();
+ for (String wkpName : wkpNames) {
+ if (wkpName.equals(defaultSession.getWorkspace().getName()))
+ addChild(new WorkspaceNode(repository, wkpName,
+ defaultSession));
+ else
+ addChild(new WorkspaceNode(repository, wkpName));
+ }
+ nodesViewer.refresh(this);
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Cannot connect to repository " + name, e);
+ }
+ }
+ }
+
+ private class WorkspaceNode extends TreeParent {
+ private final String name;
+ private final Repository repository;
+ private Session session = null;
+
+ public WorkspaceNode(Repository repository, String name) {
+ this(repository, name, null);
+ }
+
+ public WorkspaceNode(Repository repository, String name, Session session) {
+ super(name);
+ this.name = name;
+ this.repository = repository;
+ this.session = session;
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ public void login() {
+ try {
+ if (session != null)
+ session.logout();
+
+ session = repository.login(name);
+ nodesViewer.refresh(this);
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Cannot connect to repository " + name, e);
+ }
+ }
+
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.eclipse.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Thu Jul 29 10:54:11 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
--- /dev/null
+#Thu Jul 29 11:00:39 CEST 2010
+eclipse.preferences.version=1
+resolve.requirebundle=false
--- /dev/null
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = META-INF/,\
+ .
--- /dev/null
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <version>0.2.3-SNAPSHOT</version>
+ <artifactId>runtime</artifactId>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>org.argeo.eclipse.ui</artifactId>
+ <name>Commons Eclipse UI</name>
+ <packaging>jar</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${version.maven-bundle-plugin}</version>
+ <configuration>
+ <instructions>
+ <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+ <Bundle-Activator>org.argeo.eclipse.ui.ArgeoUiPlugin</Bundle-Activator>
+ <Require-Bundle>org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime</Require-Bundle>
+ <Import-Package>
+ org.springframework.beans.factory,
+ org.springframework.core.io.support,
+ !org.eclipse.core.runtime,
+ !org.eclipse.core.commands,
+ !org.eclipse.ui.plugin,
+ *
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+
+ <!-- Argeo Eclipse distribution (common dependencies for both RAP and RCP) -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.common</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <!-- JCR -->
+ <dependency>
+ <groupId>org.argeo.dep.osgi</groupId>
+ <artifactId>org.argeo.dep.osgi.jcr</artifactId>
+ </dependency>
+
+ <!-- RCP only dependency, needed at compile time -->
+ <dependency>
+ <groupId>org.argeo.commons.eclipse</groupId>
+ <artifactId>org.argeo.eclipse.dep.rcp</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Commons -->
+ <dependency>
+ <groupId>org.argeo.commons.basic</groupId>
+ <artifactId>org.argeo.basic.nodeps</artifactId>
+ <version>0.2.3-SNAPSHOT</version>
+ </dependency>
+
+ <!-- Spring -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>org.springframework.context</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>org.springframework.osgi.extender</artifactId>
+ </dependency>
+
+ <!-- Others -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
--- /dev/null
+/*\r
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.argeo.eclipse.spring;\r
+\r
+import static java.text.MessageFormat.format;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.osgi.framework.Bundle;\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.framework.BundleException;\r
+import org.osgi.framework.FrameworkUtil;\r
+import org.osgi.framework.InvalidSyntaxException;\r
+import org.osgi.util.tracker.ServiceTracker;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+/**\r
+ * @author Heiko Seeberger\r
+ * @author Mathieu Baudier\r
+ */\r
+class ApplicationContextTracker {\r
+ private final static Log log = LogFactory\r
+ .getLog(ApplicationContextTracker.class);\r
+\r
+ private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$\r
+ + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$\r
+\r
+ private ServiceTracker applicationContextServiceTracker;\r
+\r
+ /**\r
+ * @param contributorBundle\r
+ * OSGi bundle for which the Spring application context is to be\r
+ * tracked. Must not be null!\r
+ * @param factoryBundleContext\r
+ * BundleContext object which can be used to track services\r
+ * @throws IllegalArgumentException\r
+ * if the given bundle is null.\r
+ */\r
+ public ApplicationContextTracker(final Bundle contributorBundle,\r
+ final BundleContext factoryBundleContext) {\r
+ final String filter = format(FILTER,\r
+ contributorBundle.getSymbolicName());\r
+ try {\r
+ applicationContextServiceTracker = new ServiceTracker(\r
+ factoryBundleContext, FrameworkUtil.createFilter(filter),\r
+ null);\r
+ applicationContextServiceTracker.open();\r
+ } catch (final InvalidSyntaxException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void close() {\r
+ if (applicationContextServiceTracker != null) {\r
+ applicationContextServiceTracker.close();\r
+ }\r
+ }\r
+\r
+ public ApplicationContext getApplicationContext() {\r
+ ApplicationContext applicationContext = null;\r
+ if (applicationContextServiceTracker != null) {\r
+ try {\r
+ applicationContext = (ApplicationContext) applicationContextServiceTracker\r
+ .waitForService(5000);\r
+ } catch (InterruptedException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return applicationContext;\r
+ }\r
+\r
+ @Override\r
+ protected void finalize() throws Throwable {\r
+ close();\r
+ super.finalize();\r
+ }\r
+\r
+ static ApplicationContext getApplicationContext(String bundleSymbolicName) {\r
+ Bundle contributorBundle = Platform.getBundle(bundleSymbolicName);\r
+ return getApplicationContext(contributorBundle);\r
+ }\r
+\r
+ static ApplicationContext getApplicationContext(Bundle contributorBundle) {\r
+ if (log.isTraceEnabled())\r
+ log.trace("Get application context for bundle " + contributorBundle);\r
+\r
+ if (contributorBundle.getState() != Bundle.ACTIVE\r
+ && contributorBundle.getState() != Bundle.STARTING) {\r
+ try {\r
+ log.info("Starting bundle: "\r
+ + contributorBundle.getSymbolicName());\r
+ contributorBundle.start();\r
+ } catch (BundleException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+\r
+ final ApplicationContextTracker applicationContextTracker = new ApplicationContextTracker(\r
+ contributorBundle, contributorBundle.getBundleContext());\r
+ ApplicationContext applicationContext = null;\r
+ try {\r
+ applicationContext = applicationContextTracker\r
+ .getApplicationContext();\r
+ } finally {\r
+ applicationContextTracker.close();\r
+ }\r
+ return applicationContext;\r
+ }\r
+}\r
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.eclipse.spring;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.springframework.context.ApplicationContext;
+
+public class SpringCommandHandler implements IHandler {
+ private final static Log log = LogFactory
+ .getLog(SpringCommandHandler.class);
+
+ public void addHandlerListener(IHandlerListener handlerListener) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String commandId = event.getCommand().getId();
+ String bundleSymbolicName = commandId.substring(0,
+ commandId.lastIndexOf('.'));
+ try {
+ if (log.isTraceEnabled())
+ log.trace("Execute " + event + " via spring command handler "
+ + this);
+ // TODO: make it more flexible and robust
+ ApplicationContext applicationContext = ApplicationContextTracker
+ .getApplicationContext(bundleSymbolicName);
+
+ // retrieve the command via its id
+ String beanName = event.getCommand().getId();
+ if (!applicationContext.containsBean(beanName))
+ throw new ExecutionException("No bean found with name "
+ + beanName + " in bundle " + bundleSymbolicName);
+ Object bean = applicationContext.getBean(beanName);
+
+ if (!(bean instanceof IHandler))
+ throw new ExecutionException("Bean with name " + beanName
+ + " and class " + bean.getClass()
+ + " does not implement the IHandler interface.");
+
+ IHandler handler = (IHandler) bean;
+ return handler.execute(event);
+ } catch (Exception e) {
+ // TODO: use eclipse error management
+// log.error(e);
+ throw new ExecutionException("Cannot execute Spring command "
+ + commandId + " in bundle " + bundleSymbolicName, e);
+ }
+ }
+
+ public boolean isEnabled() {
+ return true;
+ }
+
+ public boolean isHandled() {
+ return true;
+ }
+
+ public void removeHandlerListener(IHandlerListener handlerListener) {
+ }
+
+}
--- /dev/null
+/*\r
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package org.argeo.eclipse.spring;\r
+\r
+import org.argeo.ArgeoException;\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IConfigurationElement;\r
+import org.eclipse.core.runtime.IExecutableExtension;\r
+import org.eclipse.core.runtime.IExecutableExtensionFactory;\r
+import org.eclipse.core.runtime.IExtension;\r
+import org.springframework.context.ApplicationContext;\r
+\r
+/**\r
+ * The Spring Extension Factory builds a bridge between the Eclipse Extension\r
+ * Registry and the Spring Framework (especially Spring Dynamic Modules).\r
+ * \r
+ * It allows you to define your extension as a spring bean within the spring\r
+ * application context of your bundle. If you would like to use this bean as an\r
+ * instance of an extension (an Eclipse RCP view, for example) you define the\r
+ * extension with this spring extension factory as the class to be created.\r
+ * \r
+ * To let the spring extension factory pick the right bean from your application\r
+ * context you need to set the bean id to the same value as the id of the view\r
+ * within the view definition, for example. This is important if your extension\r
+ * definition contains more than one element, where each element has its own id.\r
+ * \r
+ * If the extension definition elements themselves have no id attribute the\r
+ * spring extension factory uses the id of the extension itself to identify the\r
+ * bean.\r
+ * \r
+ * original code from: <a href=\r
+ * "http://martinlippert.blogspot.com/2008/10/new-version-of-spring-extension-factory.html"\r
+ * >Blog entry</a>\r
+ * \r
+ * @author Martin Lippert\r
+ * @author mbaudier\r
+ */\r
+public class SpringExtensionFactory implements IExecutableExtensionFactory,\r
+ IExecutableExtension {\r
+\r
+ private Object bean;\r
+\r
+ public Object create() throws CoreException {\r
+ if (bean == null)\r
+ throw new ArgeoException("No underlying bean for extension");\r
+ return bean;\r
+ }\r
+\r
+ public void setInitializationData(IConfigurationElement config,\r
+ String propertyName, Object data) throws CoreException {\r
+ String beanName = getBeanName(data, config);\r
+ if (beanName == null)\r
+ throw new ArgeoException("Cannot find bean name for extension "\r
+ + config);\r
+\r
+ String bundleSymbolicName = config.getContributor().getName();\r
+ ApplicationContext appContext = ApplicationContextTracker\r
+ .getApplicationContext(bundleSymbolicName);\r
+ if (appContext == null)\r
+ throw new ArgeoException(\r
+ "Cannot find application context for bundle "\r
+ + bundleSymbolicName);\r
+\r
+ this.bean = appContext.getBean(beanName);\r
+ if (this.bean instanceof IExecutableExtension) {\r
+ ((IExecutableExtension) this.bean).setInitializationData(config,\r
+ propertyName, data);\r
+ }\r
+ }\r
+\r
+ private String getBeanName(Object data, IConfigurationElement config) {\r
+\r
+ // try the specific bean id the extension defines\r
+ if (data != null && data.toString().length() > 0) {\r
+ return data.toString();\r
+ }\r
+\r
+ // try the id of the config element\r
+ if (config.getAttribute("id") != null) {\r
+ return config.getAttribute("id");\r
+ }\r
+\r
+ // try the id of the extension element itself\r
+ if (config.getParent() != null\r
+ && config.getParent() instanceof IExtension) {\r
+ IExtension extensionDefinition = (IExtension) config.getParent();\r
+ return extensionDefinition.getSimpleIdentifier();\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.eclipse.ui;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ArgeoUiPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.argeo.eclipse.ui";
+
+ private final static String SPRING_OSGI_EXTENDER = "org.springframework.osgi.extender";
+
+ // The shared instance
+ private static ArgeoUiPlugin plugin;
+
+ private BundleContext bundleContext;
+
+ /**
+ * The constructor
+ */
+ public ArgeoUiPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ bundleContext = context;
+
+ // Make sure that the Spring OSGi extender is started
+ Bundle osgiExtBundle = Platform.getBundle(SPRING_OSGI_EXTENDER);
+ if (osgiExtBundle != null)
+ osgiExtBundle.start();
+ else
+ throw new Exception("Spring OSGi Extender not found");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static ArgeoUiPlugin getDefault() {
+ return plugin;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+}
--- /dev/null
+package org.argeo.eclipse.ui;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+public abstract class GenericTableComparator extends ViewerComparator {
+
+ protected int propertyIndex;
+ public static final int ASCENDING = 0, DESCENDING = 1;
+ protected int direction = DESCENDING;
+
+ /**
+ * Creates an instance of a sorter for TableViewer.
+ *
+ * @param defaultColumn
+ * the default sorter column
+ */
+
+ public GenericTableComparator(int defaultColumnIndex, int direction) {
+ propertyIndex = defaultColumnIndex;
+ this.direction = direction;
+ }
+
+ public void setColumn(int column) {
+ if (column == this.propertyIndex) {
+ // Same column as last sort; toggle the direction
+ direction = 1 - direction;
+ } else {
+ // New column; do a descending sort
+ this.propertyIndex = column;
+ direction = DESCENDING;
+ }
+ }
+
+ /**
+ * Must be Overriden in each view.
+ */
+ public abstract int compare(Viewer viewer, Object e1, Object e2);
+}
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.eclipse.ui;
+
+public class TreeObject implements Comparable<TreeObject> {
+ private String name;
+ private TreeParent parent;
+
+ public TreeObject(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setParent(TreeParent parent) {
+ this.parent = parent;
+ }
+
+ public TreeParent getParent() {
+ return parent;
+ }
+
+ public String toString() {
+ return getName();
+ }
+
+ public int compareTo(TreeObject o) {
+ return name.compareTo(o.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(obj.toString());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.eclipse.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TreeParent extends TreeObject {
+ private List<TreeObject> children;
+
+ private boolean loaded;
+
+ public TreeParent(String name) {
+ super(name);
+ children = new ArrayList<TreeObject>();
+ loaded = false;
+ }
+
+ public synchronized void addChild(TreeObject child) {
+ loaded = true;
+ children.add(child);
+ child.setParent(this);
+ }
+
+ public synchronized void removeChild(TreeObject child) {
+ children.remove(child);
+ child.setParent(null);
+ }
+
+ public synchronized void clearChildren() {
+ loaded = false;
+ children.clear();
+ }
+
+ public synchronized TreeObject[] getChildren() {
+ return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
+ }
+
+ public synchronized boolean hasChildren() {
+ return children.size() > 0;
+ }
+
+ public TreeObject getChildByName(String name) {
+ for (TreeObject child : children) {
+ if (child.getName().equals(name))
+ return child;
+ }
+ return null;
+ }
+
+ public synchronized Boolean isLoaded() {
+ return loaded;
+ }
+}