Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew M Finkbeiner2012-03-30 16:08:39 -0400
committerRoberto E. Escobar2012-03-30 16:08:39 -0400
commita7dae8b1bcf331d25d2af7deaf8cb0ce81126f5b (patch)
treec8a2167d2b03814e08c52da3fd2249096dc88bb1 /plugins/org.eclipse.osee.ote.ui.message
parent1f7662edab16d2e93da4b6d7683a436ea57338d8 (diff)
downloadorg.eclipse.osee-a7dae8b1bcf331d25d2af7deaf8cb0ce81126f5b.tar.gz
org.eclipse.osee-a7dae8b1bcf331d25d2af7deaf8cb0ce81126f5b.tar.xz
org.eclipse.osee-a7dae8b1bcf331d25d2af7deaf8cb0ce81126f5b.zip
feature[ats_PBMQF]: Update message view to use MessageDefinitionProvider
Diffstat (limited to 'plugins/org.eclipse.osee.ote.ui.message')
-rw-r--r--plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/internal/MessageProviderVersion.java35
-rw-r--r--plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/tree/MessageTreeBuilder.java40
-rw-r--r--plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageDefinitionProviderTracker.java30
-rw-r--r--plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageView.java95
4 files changed, 155 insertions, 45 deletions
diff --git a/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/internal/MessageProviderVersion.java b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/internal/MessageProviderVersion.java
new file mode 100644
index 0000000000..8f74d350fe
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/internal/MessageProviderVersion.java
@@ -0,0 +1,35 @@
+package org.eclipse.osee.ote.ui.message.internal;
+
+import java.util.Set;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+import org.eclipse.osee.ote.message.MessageDefinitionProvider;
+
+public class MessageProviderVersion {
+ Set<String> versions = new ConcurrentSkipListSet<String>();
+
+ public void add(MessageDefinitionProvider provider){
+ versions.add(generateVersion(provider));
+ }
+
+ public void remove(MessageDefinitionProvider provider){
+ versions.remove(generateVersion(provider));
+ }
+
+ public String getVersion(){
+ if(versions.size() == 0){
+ return "no library detected";
+ }
+ StringBuilder sb = new StringBuilder();
+ for(String ver:versions){
+ sb.append(ver);
+ sb.append("\n");
+ }
+ sb.deleteCharAt(sb.length()-1);
+ return sb.toString();
+ }
+
+ private String generateVersion(MessageDefinitionProvider provider){
+ return String.format("%s[%s.%s]", provider.singletonId(), provider.majorVersion(), provider.minorVersion());
+ }
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/tree/MessageTreeBuilder.java b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/tree/MessageTreeBuilder.java
index e6b5adea15..43935b5ea7 100644
--- a/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/tree/MessageTreeBuilder.java
+++ b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/tree/MessageTreeBuilder.java
@@ -14,6 +14,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+
+import org.eclipse.osee.ote.message.MessageDefinitionProvider;
import org.eclipse.osee.ote.message.MessageSink;
/**
@@ -27,8 +29,10 @@ public class MessageTreeBuilder implements MessageSink {
private ArrayList<String> lastAddedMsgNode;
private int numElements = 0;
private int numMessages = 0;
- private final HashMap<String, ArrayList<String>> msgs = new HashMap<String, ArrayList<String>>(200000);
-
+ private HashMap<String, ArrayList<String>> currentMsgs;
+ private Collection<Map.Entry<String, ArrayList<String>>> allMessages = new ArrayList<Map.Entry<String, ArrayList<String>>>(200000);
+ private final HashMap<MessageDefinitionProvider, HashMap<String, ArrayList<String>>> msgs = new HashMap<MessageDefinitionProvider, HashMap<String, ArrayList<String>>>();
+
public void clear() {
numMessages = numElements = 0;
msgs.clear();
@@ -47,7 +51,7 @@ public class MessageTreeBuilder implements MessageSink {
@Override
public void absorbMessage(String messageName) {
lastAddedMsgNode = new ArrayList<String>(64);
- msgs.put(messageName, lastAddedMsgNode);
+ currentMsgs.put(messageName, lastAddedMsgNode);
numMessages++;
}
@@ -69,7 +73,35 @@ public class MessageTreeBuilder implements MessageSink {
}
public Collection<Map.Entry<String, ArrayList<String>>> getMessages() {
- return msgs.entrySet();
+ return allMessages;
+ }
+
+ private void buildAllMsgs(){
+ allMessages.clear();
+ for(HashMap<String, ArrayList<String>> val:msgs.values()){
+ allMessages.addAll(val.entrySet());
+ }
+ }
+
+ public void startProcessing(MessageDefinitionProvider provider) {
+ currentMsgs = new HashMap<String, ArrayList<String>>(200000);
+ msgs.put(provider, currentMsgs);
+ }
+
+ public void stopProcessing(MessageDefinitionProvider provider) {
+ buildAllMsgs();
+ currentMsgs = null;
+ }
+
+ public void removeProvider(MessageDefinitionProvider service) {
+ if(msgs.remove(service) == null){
+ System.out.println("didn't remove anything");
+ }
+ buildAllMsgs();
+ }
+
+ public int getNumProviders() {
+ return msgs.size();
}
}
diff --git a/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageDefinitionProviderTracker.java b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageDefinitionProviderTracker.java
new file mode 100644
index 0000000000..0252abc86d
--- /dev/null
+++ b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageDefinitionProviderTracker.java
@@ -0,0 +1,30 @@
+package org.eclipse.osee.ote.ui.message.view;
+
+import org.eclipse.osee.ote.message.MessageDefinitionProvider;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+
+class MessageDefinitionProviderTracker extends ServiceTracker<MessageDefinitionProvider, MessageDefinitionProvider> {
+
+ private final MessageView view;
+
+ public MessageDefinitionProviderTracker(BundleContext context, MessageView view){
+ super(context, MessageDefinitionProvider.class.getName(), null);
+ this.view = view;
+ }
+
+ @Override
+ public MessageDefinitionProvider addingService(ServiceReference<MessageDefinitionProvider> reference) {
+ MessageDefinitionProvider provider = super.addingService(reference);
+ view.addMessageDefinitionProvider(provider);
+ return provider;
+ }
+
+ @Override
+ public void removedService(ServiceReference<MessageDefinitionProvider> reference, MessageDefinitionProvider service) {
+ view.removeMessageDefinitionProvider(service);
+ super.removedService(reference, service);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageView.java b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageView.java
index e7a30fec96..7f4f6c845a 100644
--- a/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageView.java
+++ b/plugins/org.eclipse.osee.ote.ui.message/src/org/eclipse/osee/ote/ui/message/view/MessageView.java
@@ -19,6 +19,7 @@ import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -36,10 +37,10 @@ import org.eclipse.osee.framework.ui.plugin.util.HelpUtil;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.osee.framework.ui.swt.Widgets;
-import org.eclipse.osee.ote.service.IMessageDictionary;
-import org.eclipse.osee.ote.service.IMessageDictionaryListener;
+import org.eclipse.osee.ote.message.MessageDefinitionProvider;
import org.eclipse.osee.ote.ui.message.OteMessageImage;
import org.eclipse.osee.ote.ui.message.internal.Activator;
+import org.eclipse.osee.ote.ui.message.internal.MessageProviderVersion;
import org.eclipse.osee.ote.ui.message.tree.AbstractTreeNode;
import org.eclipse.osee.ote.ui.message.tree.ElementNode;
import org.eclipse.osee.ote.ui.message.tree.MessageContentProvider;
@@ -77,8 +78,9 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
+import org.osgi.framework.FrameworkUtil;
-public class MessageView extends ViewPart implements IMessageDictionaryListener {
+public class MessageView extends ViewPart {
protected TreeViewer treeViewer;
protected Text searchText;
protected MessageViewLabelProvider labelProvider;
@@ -92,9 +94,14 @@ public class MessageView extends ViewPart implements IMessageDictionaryListener
private int numMessages = 0;
private int numElements = 0;
private MessageTreeBuilder treeBuilder;
+
+ private MessageDefinitionProviderTracker tracker;
+ private MessageProviderVersion messageProviderVersion;
+
public MessageView() {
super();
+ messageProviderVersion = new MessageProviderVersion();
}
@Override
@@ -217,7 +224,8 @@ public class MessageView extends ViewPart implements IMessageDictionaryListener
treeViewer.setInput(root);
setHelpContexts();
setLibraryUnloadedState();
- Activator.getDefault().getOteClientService().addDictionaryListener(this);
+ tracker = new MessageDefinitionProviderTracker(FrameworkUtil.getBundle(getClass()).getBundleContext(), this);
+ tracker.open(true);
}
private void setHelpContexts() {
@@ -517,42 +525,6 @@ public class MessageView extends ViewPart implements IMessageDictionaryListener
parentComposite.setFocus();
}
- @Override
- public void onDictionaryLoaded(final IMessageDictionary dictionary) {
- Displays.pendInDisplayThread(new Runnable() {
- @Override
- public void run() {
- try {
- startLabel.setText("processing library...");
- treeViewer.getTree().setBackground(Displays.getSystemColor(SWT.COLOR_WHITE));
- treeBuilder.clear();
- dictionary.generateMessageIndex(treeBuilder);
- numMessages = treeBuilder.getNumMessages();
- numElements = treeBuilder.getNumElements();
- treeViewer.getTree().setToolTipText(
- String.format("#Messages: %d, #Elements: %d\n\nProviders:\n%s", numMessages, numElements,
- dictionary.getMessageLibraryVersion()));
- searchText.setEnabled(true);
- startLabel.setText("Ready for query");
- } catch (Exception e) {
- OseeLog.log(Activator.class, Level.SEVERE, "Problem during message jar processing", e);
- }
- }
- });
- }
-
- @Override
- public void onDictionaryUnloaded(IMessageDictionary dictionary) {
- Displays.pendInDisplayThread(new Runnable() {
- @Override
- public void run() {
- setLibraryUnloadedState();
- }
-
- });
-
- }
-
private void setLibraryUnloadedState() {
if (treeViewer.getTree().isDisposed() || startLabel.isDisposed() || searchText.isDisposed()) {
return;
@@ -566,8 +538,49 @@ public class MessageView extends ViewPart implements IMessageDictionaryListener
@Override
public void dispose() {
+ tracker.close();
super.dispose();
- Activator.getDefault().getOteClientService().removeDictionaryListener(this);
}
+ public void addMessageDefinitionProvider(final MessageDefinitionProvider provider) {
+ messageProviderVersion.add(provider);
+ Displays.pendInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ startLabel.setText("processing library...");
+ treeViewer.getTree().setBackground(Displays.getSystemColor(SWT.COLOR_WHITE));
+ treeBuilder.startProcessing(provider);
+ provider.generateMessageIndex(treeBuilder);
+ treeBuilder.stopProcessing(provider);
+ treeViewer.getTree().setToolTipText(
+ String.format("Providers:\n%s", messageProviderVersion.getVersion()));
+ searchText.setEnabled(true);
+ startLabel.setText("Ready for query");
+ } catch (Exception e) {
+ OseeLog.log(Activator.class, Level.SEVERE, "Problem during message jar processing", e);
+ }
+ }
+ });
+ }
+
+ public void removeMessageDefinitionProvider(final MessageDefinitionProvider service) {
+ messageProviderVersion.remove(service);
+ Displays.pendInDisplayThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ treeBuilder.removeProvider(service);
+ if(treeBuilder.getNumProviders() == 0){
+ setLibraryUnloadedState();
+ } else {
+ treeViewer.getTree().setToolTipText(String.format("Providers:\n%s", messageProviderVersion.getVersion()));
+ }
+ } catch (Exception e) {
+ OseeLog.log(Activator.class, Level.SEVERE, "Problem during message jar processing", e);
+ }
+ }
+ });
+ }
+
} \ No newline at end of file

Back to the top