From: <bea...@us...> - 2006-10-13 17:22:23
|
Revision: 273 http://svn.sourceforge.net/cishell/?rev=273&view=rev Author: bearsfan Date: 2006-10-13 10:22:17 -0700 (Fri, 13 Oct 2006) Log Message: ----------- getsaveservice and checked for current UI thread Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2006-10-13 17:18:53 UTC (rev 272) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2006-10-13 17:22:17 UTC (rev 273) @@ -10,6 +10,7 @@ Eclipse-LazyStart: true Import-Package: org.cishell.app.service.datamanager, org.cishell.framework, + org.cishell.framework.algorithm, org.cishell.framework.data, org.osgi.service.log;version="1.3.0" Export-Package: org.cishell.reference.gui.datamanager Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2006-10-13 17:18:53 UTC (rev 272) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2006-10-13 17:22:17 UTC (rev 273) @@ -16,6 +16,7 @@ import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; +import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -23,6 +24,8 @@ import org.cishell.app.service.datamanager.DataManagerListener; import org.cishell.app.service.datamanager.DataManagerService; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.eclipse.jface.viewers.ISelection; @@ -84,9 +87,13 @@ private Menu menu; private Map dataToDataGUIItemMap; + + private AlgorithmFactory saveFactory; private DiscardListener discardListener; + private SaveListener saveListener; + public AbstractDataManagerView(String brandPluginID) { manager = Activator.getDataManagerService(); this.brandPluginID = brandPluginID; @@ -124,7 +131,14 @@ MenuItem saveItem = new MenuItem(menu, SWT.PUSH); saveItem.setText("Save"); - saveItem.setEnabled(false); + this.saveFactory = Activator.getSaveService(); + if (this.saveFactory != null) { + saveListener = new SaveListener(); + saveItem.addListener(SWT.Selection, saveListener); + } + else { + saveItem.setEnabled(false); + } MenuItem renameItem = new MenuItem(menu, SWT.PUSH); renameItem.setText("Rename"); @@ -191,7 +205,8 @@ // update the ModelManager with the new selection final Set selection = new HashSet(); selection.add(data); - Display.getDefault().syncExec(new Runnable() { + + guiRun(new Runnable() { public void run() { if (!tree.isDisposed()) { // update the TreeView @@ -206,6 +221,14 @@ } }); } + + private void guiRun(Runnable run) { + if (Thread.currentThread() == Display.getDefault().getThread()) { + run.run(); + } else { + Display.getDefault().syncExec(run); + } + } public void dataLabelChanged(Data data, String label) { if (data != null && label != null) { @@ -231,7 +254,7 @@ public void dataSelected(final Data[] data) { if (data != null) { //setFocus(); - Display.getDefault().syncExec(new Runnable() { + guiRun(new Runnable() { public void run() { Set itemSet = new HashSet(); for (int i = 0; i < data.length; ++i) { @@ -396,6 +419,20 @@ } } + + private class SaveListener implements Listener { + public void handleEvent(Event event) { + if (AbstractDataManagerView.this.saveFactory != null) { + TreeItem[] selection = AbstractDataManagerView.this.tree.getSelection(); + Data data = ((DataGUIItem)selection[0].getData()).getModel(); + Algorithm algorithm = AbstractDataManagerView.this.saveFactory.createAlgorithm(new Data[]{data}, + new Hashtable(), + Activator.getCIShellContext()); + algorithm.execute(); + } + } + } + private class DiscardListener implements Listener { public void handleEvent(Event event) { TreeItem[] selection = AbstractDataManagerView.this.tree Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2006-10-13 17:18:53 UTC (rev 272) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2006-10-13 17:22:17 UTC (rev 273) @@ -1,8 +1,14 @@ package org.cishell.reference.gui.datamanager; import org.cishell.app.service.datamanager.DataManagerService; +import org.cishell.framework.CIShellContext; +import org.cishell.framework.LocalCIShellContext; +import org.cishell.framework.algorithm.AlgorithmFactory; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; /** @@ -65,4 +71,24 @@ return log; } + + protected static AlgorithmFactory getSaveService() { + ServiceReference[] refs; + try { + refs = context.getServiceReferences(AlgorithmFactory.class.getName(), + "(&("+Constants.SERVICE_PID+"=org.cishell.reference.gui.persistence.save.Save))"); + if (refs != null && refs.length > 0) { + return (AlgorithmFactory) context.getService(refs[0]); + } else { + return null; + } + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + return null; + } + } + + protected static CIShellContext getCIShellContext() { + return new LocalCIShellContext(context); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |