summaryrefslogtreecommitdiff
path: root/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event')
-rw-r--r--src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/IKeyStoreModelListener.java62
-rw-r--r--src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEvent.java67
-rw-r--r--src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEventManager.java116
3 files changed, 245 insertions, 0 deletions
diff --git a/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/IKeyStoreModelListener.java b/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/IKeyStoreModelListener.java
new file mode 100644
index 0000000..19e24a4
--- /dev/null
+++ b/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/IKeyStoreModelListener.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 com.motorolamobility.studio.android.certmanager.event;
+
+import com.motorolamobility.studio.android.certmanager.ui.model.ITreeNode;
+
+/**
+ * This interface must be implemented by listeners to events occurred on the {@link ITreeNode}.
+ */
+public interface IKeyStoreModelListener
+{
+ /**
+ * Handles the event {@link KeyStoreModelEvent#EventType} to add a node.
+ * @param keyStoreModelEvent {@link KeyStoreModelEvent#getTreeNodeItem()} contains the node to be added.
+ */
+ public void handleNodeAdditionEvent(KeyStoreModelEvent keyStoreModeEvent);
+
+ /**
+ * Handles the event {@link KeyStoreModelEvent#EventType} to remove a node.
+ * @param keyStoreModelEvent {@link KeyStoreModelEvent#getTreeNodeItem()} contains the node to be added.
+ */
+ public void handleNodeRemovalEvent(KeyStoreModelEvent keyStoreModeEvent);
+
+ /**
+ * Handles the event {@link KeyStoreModelEvent#EventType} to update a node.
+ * @param keyStoreModelEvent {@link KeyStoreModelEvent#getTreeNodeItem()} contains the node to be added.
+ */
+ public void handleNodeUpdateEvent(KeyStoreModelEvent keyStoreModeEvent);
+
+ /**
+ * Handles the event {@link KeyStoreModelEvent#EventType} to collapse a node.
+ * @param keyStoreModelEvent {@link KeyStoreModelEvent#getTreeNodeItem()} contains the node to be collapsed.
+ */
+ public void handleNodeCollapseEvent(KeyStoreModelEvent keyStoreModelEvent);
+
+ /**
+ * Handles the event {@link KeyStoreModelEvent#EventType} to refresh a node.
+ * @param keyStoreModelEvent {@link KeyStoreModelEvent#getTreeNodeItem()} contains the node to be refreshed.
+ */
+ public void handleNodeRefreshEvent(KeyStoreModelEvent keyStoreModelEvent);
+
+ /**
+ * Handles the event {@link KeyStoreModelEvent#EventType} to clear a node.
+ * @param keyStoreModelEvent {@link KeyStoreModelEvent#getTreeNodeItem()} contains the node to be cleared.
+ */
+ public void handleNodeClearEvent(KeyStoreModelEvent keyStoreModelEvent);
+
+}
diff --git a/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEvent.java b/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEvent.java
new file mode 100644
index 0000000..9ff4dd0
--- /dev/null
+++ b/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEvent.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 com.motorolamobility.studio.android.certmanager.event;
+
+import com.motorolamobility.studio.android.certmanager.ui.model.ITreeNode;
+
+/**
+ * This class represents an event occurred on the {@link ITreeNode}.
+ */
+public class KeyStoreModelEvent
+{
+ private final EventType eventType;
+
+ private final ITreeNode treeNodeItem;
+
+ /**
+ * Represents the change in the model. The {@link KeyStoreModelEvent#treeNodeItem} in each event may vary as specified below:
+ * <ul>
+ * <li>{@link EVENT_TYPE#ADD} it is the item that needs to be added</li>
+ * <li>{@link EVENT_TYPE#REMOVE} it is the item that needs to be deleted</li>
+ * <li>{@link EVENT_TYPE#UPDATE} it is the item that needs to be updated</li>
+ * </ul>
+ */
+ public enum EventType
+ {
+ ADD, REMOVE, UPDATE, COLLAPSE, REFRESH, CLEAR
+ }
+
+ /**
+ * Returns the event type.
+ * */
+ public EventType getEventType()
+ {
+ return eventType;
+ }
+
+ /**
+ * Returns the tree node item related to the event.
+ * */
+ public ITreeNode getTreeNodeItem()
+ {
+ return treeNodeItem;
+ }
+
+ /**
+ * Constructs a new event given an {@link ITreeNode} and a {@link KeyStoreModelEvent#EventType}.
+ * */
+ public KeyStoreModelEvent(ITreeNode treeNodeItem, EventType eventType)
+ {
+ this.eventType = eventType;
+ this.treeNodeItem = treeNodeItem;
+ }
+}
diff --git a/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEventManager.java b/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEventManager.java
new file mode 100644
index 0000000..5e2b49b
--- /dev/null
+++ b/src/plugins/certmanager/src/com/motorolamobility/studio/android/certmanager/event/KeyStoreModelEventManager.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * 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 com.motorolamobility.studio.android.certmanager.event;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.motorolamobility.studio.android.certmanager.ui.model.ITreeNode;
+
+/**
+ * Manager which notifies {@link IKeyStoreModelListener} registered that a {@link KeyStoreModelEvent} occurred.
+ * It is a singleton that needs to be called by the hierarchy of {@link ITreeNode} items when they modify the {@link ITreeNode}.
+ */
+public class KeyStoreModelEventManager
+{
+ private static KeyStoreModelEventManager _instance;
+
+ private final List<IKeyStoreModelListener> listeners = new ArrayList<IKeyStoreModelListener>();
+
+ private KeyStoreModelEventManager()
+ {
+ // Singleton - private default constructor prevents instantiations by other classes.
+ }
+
+ /**
+ * Return the singleton instance of KeyStoreModelEventManager.
+ * */
+ public synchronized static KeyStoreModelEventManager getInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new KeyStoreModelEventManager();
+ }
+ return _instance;
+ }
+
+ /**
+ * Add the parameter {@code listener} to the list of KeyStore event listeners.
+ * @param listener The listener to be added.
+ * */
+ public void addListener(IKeyStoreModelListener listener)
+ {
+ synchronized (listener)
+ {
+ listeners.add(listener);
+ }
+ }
+
+ /**
+ * Remove the parameter {@code listener} to the list of KeyStore event listeners.
+ * @param listener The listener to be removed.
+ * */
+ public void removeListener(IKeyStoreModelListener listener)
+ {
+ synchronized (listener)
+ {
+ listeners.remove(listener);
+ }
+ }
+
+ /**
+ * Fire/notify/deliver the event to registered listeners.
+ * @param node {@link ITreeNode} that needs to refresh the view based on the model
+ * @param eventType Event that occurred.
+ */
+ public void fireEvent(ITreeNode treeNodeItem, KeyStoreModelEvent.EventType eventType)
+ {
+ KeyStoreModelEvent keyStoreModelEvent = new KeyStoreModelEvent(treeNodeItem, eventType);
+ synchronized (listeners)
+ {
+ if (listeners != null)
+ {
+ for (IKeyStoreModelListener listener : listeners)
+ {
+ switch (eventType)
+ {
+ case ADD:
+ listener.handleNodeAdditionEvent(keyStoreModelEvent);
+ break;
+ case REMOVE:
+ listener.handleNodeRemovalEvent(keyStoreModelEvent);
+ break;
+ case UPDATE:
+ listener.handleNodeUpdateEvent(keyStoreModelEvent);
+ break;
+ case COLLAPSE:
+ listener.handleNodeCollapseEvent(keyStoreModelEvent);
+ break;
+ case REFRESH:
+ listener.handleNodeRefreshEvent(keyStoreModelEvent);
+ break;
+ case CLEAR:
+ listener.handleNodeClearEvent(keyStoreModelEvent);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+}