ui: bookmarks

can now bookmark tokens
This commit is contained in:
wrongway88
2017-02-12 15:06:07 +01:00
parent e1d2c3a4e0
commit 97fd40fe9b
84 changed files with 5024 additions and 65 deletions
+10
View File
@@ -1,6 +1,7 @@
#include "component/ComponentFactory.h"
#include "component/Component.h"
#include "component/controller/BookmarkController.h"
#include "component/controller/CodeController.h"
#include "component/controller/ErrorController.h"
#include "component/controller/FeatureController.h"
@@ -11,6 +12,7 @@
#include "component/controller/StatusBarController.h"
#include "component/controller/StatusController.h"
#include "component/controller/UndoRedoController.h"
#include "component/view/BookmarkView.h"
#include "component/view/CodeView.h"
#include "component/view/ErrorView.h"
#include "component/view/GraphView.h"
@@ -48,6 +50,14 @@ StorageAccess* ComponentFactory::getStorageAccess() const
return m_storageAccess;
}
std::shared_ptr<Component> ComponentFactory::createBookmarkComponent(ViewLayout* viewLayout)
{
std::shared_ptr<BookmarkView> view = m_viewFactory->createBookmarkView(viewLayout);
std::shared_ptr<BookmarkController> controller = std::make_shared<BookmarkController>(m_storageAccess);
return std::make_shared<Component>(view, controller);
}
std::shared_ptr<Component> ComponentFactory::createCodeComponent(ViewLayout* viewLayout)
{
std::shared_ptr<CodeView> view = m_viewFactory->createCodeView(viewLayout);
+1
View File
@@ -19,6 +19,7 @@ public:
ViewFactory* getViewFactory() const;
StorageAccess* getStorageAccess() const;
std::shared_ptr<Component> createBookmarkComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createCodeComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createErrorComponent(ViewLayout* viewLayout);
std::shared_ptr<Component> createFeatureComponent();
+3
View File
@@ -33,6 +33,9 @@ void ComponentManager::setup(ViewLayout* viewLayout)
m_componentFactory->getViewFactory()->createCompositeView(viewLayout, CompositeView::DIRECTION_HORIZONTAL, "Search");
m_compositeViews.push_back(compositeView);
std::shared_ptr<Component> bookmarkComponent = m_componentFactory->createBookmarkComponent(compositeView.get());
m_components.push_back(bookmarkComponent);
std::shared_ptr<Component> undoRedoComponent = m_componentFactory->createUndoRedoComponent(compositeView.get());
m_components.push_back(undoRedoComponent);
@@ -0,0 +1,727 @@
#include "BookmarkController.h"
#include "component/view/BookmarkView.h"
#include "data/access/StorageAccess.h"
#include "data/bookmark/Bookmark.h"
#include "data/location/TokenLocation.h"
#include "data/location/TokenLocationCollection.h"
#include "data/location/TokenLocationFile.h"
#include "utility/messaging/type/MessageActivateEdge.h"
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/logging/logging.h"
#include "utility/utilityString.h"
#include "data/bookmark/EdgeBookmark.h"
#include "data/bookmark/NodeBookmark.h"
const std::string BookmarkController::m_edgeSeperatorToken = "=>";
BookmarkController::BookmarkController(StorageAccess* storageAccess)
: m_storageAccess(storageAccess)
, m_activeTokens()
, m_activeTokenNames()
, m_activeTokenDisplayNames()
, m_activeTokenTypes()
, m_activeEdges()
, m_activeEdgeNames()
, m_activeEdgeDisplayNames()
, m_activeEdgeTypes()
, m_activeTokenExists(false)
{
}
BookmarkController::~BookmarkController()
{
}
void BookmarkController::clear()
{
}
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getAllBookmarks() const
{
LOG_INFO_STREAM(<< "Retrieving all bookmarks");
std::vector<std::shared_ptr<Bookmark>> bookmarks;
std::vector<NodeBookmark> nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
for (unsigned int i = 0; i < nodeBookmarks.size(); i++)
{
bookmarks.push_back(std::make_shared<NodeBookmark>(nodeBookmarks[i]));
}
std::vector<EdgeBookmark> edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
for (unsigned int i = 0; i < edgeBookmarks.size(); i++)
{
bookmarks.push_back(std::make_shared<EdgeBookmark>(edgeBookmarks[i]));
}
// std::vector<Bookmark> bookmarks = m_storageAccess->getAllBookmarks();
// check whether bookmarks are still valid (so, no referenced tokens have been removed)
for (unsigned int i = 0; i < bookmarks.size(); i++)
{
for (unsigned int j = 0; j < bookmarks[i]->getTokenNames().size(); j++)
{
std::string name = bookmarks[i]->getTokenNames()[j];
int type = bookmarks[i]->getTokenTypes()[j];
bool exists = false;
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) != NULL)
{
TempEdge tmpEdge = getEdge(name, type);
exists = m_storageAccess->checkEdgeExists(tmpEdge.edgeId);
}
else
{
exists = m_storageAccess->checkNodeExistsByName(name);
}
std::vector<Id> tokenIds = bookmarks[i]->getTokenIds();
bookmarks[i]->setValid(exists);
}
}
return bookmarks;
}
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getBookmarks(const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const
{
LOG_INFO_STREAM(<< "Retrieving bookmarks with filter '" << std::to_string(filter) << "' and order '" << std::to_string(order) << "'");
std::vector<std::shared_ptr<Bookmark>> bookmarks = getAllBookmarks();
int bookmarkCount = bookmarks.size();
bookmarks = getFilteredBookmarks(bookmarks, filter);
bookmarkCount = bookmarks.size();
bookmarks = getOrderedBookmarks(bookmarks, order);
return bookmarks;
}
std::vector<std::string> BookmarkController::getActiveTokenNames() const
{
return m_activeTokenNames;
}
std::vector<std::string> BookmarkController::getActiveTokenDisplayNames() const
{
if (m_activeEdgeDisplayNames.size() > 0)
{
return m_activeEdgeDisplayNames;
}
else
{
return m_activeTokenDisplayNames;
}
}
std::vector<BookmarkCategory> BookmarkController::getAllBookmarkCategories() const
{
return m_storageAccess->getAllBookmarkCategories();
}
bool BookmarkController::activeTokenExists() const
{
return m_activeTokenExists;
}
std::shared_ptr<Bookmark> BookmarkController::getBookmarkForActiveToken() const
{
if (m_activeEdgeNames.size() > 0)
{
std::vector<EdgeBookmark> bookmarks = m_storageAccess->getAllEdgeBookmarks();
for (unsigned int i = 0; i < bookmarks.size(); i++)
{
if (bookmarks[i].getTokenNames() == m_activeEdgeNames)
{
return std::make_shared<EdgeBookmark>(bookmarks[i]);
}
}
}
else
{
std::vector<NodeBookmark> bookmarks = m_storageAccess->getAllNodeBookmarks();
for (unsigned int i = 0; i < bookmarks.size(); i++)
{
if (bookmarks[i].getTokenNames() == m_activeTokenNames)
{
return std::make_shared<NodeBookmark>(bookmarks[i]);
}
}
}
return NULL;
}
void BookmarkController::handleMessage(MessageActivateBookmark* message)
{
LOG_INFO_STREAM(<< "Attempting to activate Bookmark");
if (dynamic_cast<EdgeBookmark*>(message->bookmark.get()) != NULL)
{
EdgeBookmark* bookmark = dynamic_cast<EdgeBookmark*>(message->bookmark.get());
NodeBookmark baseBookmark = bookmark->getBaseBookmark();
MessageActivateNodes activateNodes;
for (unsigned int i = 0; i < baseBookmark.getTokenNames().size(); i++)
{
NameHierarchy nh = NameHierarchy::deserialize(baseBookmark.getTokenNames()[i]);
activateNodes.addNode(nh);
}
activateNodes.dispatch();
NameHierarchy source;
NameHierarchy target;
for (unsigned int i = 0; i < bookmark->getTokenNames().size(); i++)
{
int tokenType = bookmark->getTokenTypes()[i];
TempEdge tmpEdge = getEdge(bookmark->getTokenNames()[i], tokenType);
MessageActivateEdge activateEdge(tmpEdge.edgeId, Edge::intToType(tokenType), tmpEdge.source, tmpEdge.target);
activateEdge.dispatch();
}
}
else
{
NodeBookmark* bookmark = dynamic_cast<NodeBookmark*>(message->bookmark.get());
MessageActivateNodes activateNodes;
for (unsigned int i = 0; i < bookmark->getTokenNames().size(); i++)
{
NameHierarchy nh = NameHierarchy::deserialize(bookmark->getTokenNames()[i]);
activateNodes.addNode(nh);
}
activateNodes.dispatch();
}
}
void BookmarkController::handleMessage(MessageActivateTokens* message)
{
LOG_INFO_STREAM(<< "Registering new active token");
if (message->isEdge)
{
LOG_INFO_STREAM(<< "Registering new Edge");
std::vector<std::string> tokenNames;
std::vector<std::string> tokenDisplayNames;
std::vector<int> tokenTypes;
for (unsigned int i = 0; i < message->tokenIds.size(); i++)
{
StorageEdge edge = m_storageAccess->getEdgeById(message->tokenIds[i]);
int typeId = edge.type;
tokenTypes.push_back(typeId);
NameHierarchy sourceHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(edge.sourceNodeId);
NameHierarchy targetHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(edge.targetNodeId);
std::string sourceNode = NameHierarchy::serialize(sourceHierarchy);
std::string targetNode = NameHierarchy::serialize(targetHierarchy);
std::string tokenName = sourceNode + m_edgeSeperatorToken + targetNode;
tokenNames.push_back(tokenName);
tokenDisplayNames.push_back(sourceHierarchy.getRawName() + m_edgeSeperatorToken + targetHierarchy.getRawName());
}
m_activeEdges = message->tokenIds;
m_activeEdgeNames = tokenNames;
m_activeEdgeTypes = tokenTypes;
m_activeEdgeDisplayNames = tokenDisplayNames;
if (m_storageAccess->checkEdgeBookmarkExistsByTokens(tokenNames))
{
m_activeTokenExists = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
}
else
{
m_activeTokenExists = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
}
}
else
{
LOG_INFO_STREAM(<< "Registering new Node");
m_activeTokens = message->tokenIds;
m_activeTokenNames = getTokenNames(m_activeTokens);
m_activeTokenTypes = getTokenTypes(m_activeTokens);
m_activeTokenDisplayNames = getTokenDisplayNames(m_activeTokens);
m_activeEdges.clear();
m_activeEdgeNames.clear();
m_activeEdgeTypes.clear();
m_activeEdgeDisplayNames.clear();
if (m_storageAccess->checkNodeBookmarkExistsByTokens(m_activeTokenNames))
{
m_activeTokenExists = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
}
else
{
m_activeTokenExists = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
}
}
}
void BookmarkController::handleMessage(MessageCreateBookmark* message)
{
LOG_INFO_STREAM(<< "Attempting to create new bookmark");
if (m_activeTokens.size() > 0)
{
if (m_activeEdges.size() > 0)
{
LOG_INFO_STREAM(<< "Creating Edge Bookmark");
std::string displayName = message->displayName;
if (displayName.size() <= 0)
{
displayName = getDisplayName(m_activeTokens[0]);
}
EdgeBookmark bookmark(displayName, m_activeTokens, m_activeTokenNames, message->comment, TimePoint::now());
bookmark.setDisplayName(message->displayName);
bookmark.setComment(message->comment);
bookmark.setTokenTypes(m_activeTokenTypes);
BookmarkCategory category;
category.setName(message->categoryName);
bookmark.setCategory(category);
bookmark.setEdgeTokenIds(m_activeEdges);
bookmark.setEdgeTokenNames(m_activeEdgeNames);
bookmark.setEdgeTokenTypes(m_activeEdgeTypes);
Id id = m_storageAccess->addEdgeBookmark(bookmark);
bookmark.setId(id);
m_activeTokenExists = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
getView<BookmarkView>()->update();
}
else
{
LOG_INFO_STREAM(<< "Creating Node Bookmark");
std::string displayName = message->displayName;
if (displayName.size() <= 0)
{
displayName = getDisplayName(m_activeTokens[0]);
}
NodeBookmark bookmark(displayName, m_activeTokens, m_activeTokenNames, message->comment, TimePoint::now());
bookmark.setTokenTypes(m_activeTokenTypes);
BookmarkCategory category;
category.setName(message->categoryName);
bookmark.setCategory(category);
Id id = m_storageAccess->addNodeBookmark(bookmark);
bookmark.setId(id);
m_activeTokenExists = true;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::ALREADY_CREATED);
getView<BookmarkView>()->update();
}
}
}
void BookmarkController::handleMessage(MessageCreateBookmarkCategory* message)
{
std::string categoryName = message->name;
LOG_INFO_STREAM(<< "Attempting to create new Bookmark category '" << categoryName << "'");
if (m_storageAccess->checkBookmarkCategoryExists(message->name) == false)
{
BookmarkCategory category;
category.setName(message->name);
m_storageAccess->addBookmarkCategory(category);
}
}
void BookmarkController::handleMessage(MessageDeleteBookmark* message)
{
LOG_INFO_STREAM(<< "Attempting to delete Bookmark " << std::to_string(message->bookmarkId));
if (message->isEdge)
{
m_storageAccess->removeEdgeBookmark(message->bookmarkId);
}
else
{
m_storageAccess->removeNodeBookmark(message->bookmarkId);
}
cleanBookmarkCategories();
getView<BookmarkView>()->update();
}
void BookmarkController::handleMessage(MessageDeleteBookmarkCategoryWithBookmarks* message)
{
std::vector<BookmarkCategory> categories = m_storageAccess->getAllBookmarkCategories();
for (unsigned int i = 0; i < categories.size(); i++)
{
if (categories[i].getId() == message->categoryId)
{
std::vector<NodeBookmark> nodeBookmarks = m_storageAccess->getAllNodeBookmarks();
for (unsigned int j = 0; j < nodeBookmarks.size(); j++)
{
if (nodeBookmarks[j].getCategory().getName() == categories[i].getName())
{
m_storageAccess->removeNodeBookmark(nodeBookmarks[j].getId());
}
}
std::vector<EdgeBookmark> edgeBookmarks = m_storageAccess->getAllEdgeBookmarks();
for (unsigned int j = 0; j < edgeBookmarks.size(); j++)
{
if (edgeBookmarks[j].getCategory().getName() == categories[i].getName())
{
m_storageAccess->removeEdgeBookmark(edgeBookmarks[j].getId());
}
}
cleanBookmarkCategories();
getView<BookmarkView>()->update();
return;
}
}
}
void BookmarkController::handleMessage(MessageDeleteBookmarkForActiveTokens* message)
{
std::shared_ptr<Bookmark> bookmark = getBookmarkForActiveToken();
if (bookmark != NULL)
{
LOG_INFO_STREAM(<< "Deleting bookmark " << bookmark->getDisplayName());
if (dynamic_cast<EdgeBookmark*>(bookmark.get()) != NULL)
{
m_storageAccess->removeEdgeBookmark(bookmark->getId());
}
else if(dynamic_cast<NodeBookmark*>(bookmark.get()) != NULL)
{
m_storageAccess->removeNodeBookmark(bookmark->getId());
}
cleanBookmarkCategories();
m_activeTokenExists = false;
getView<BookmarkView>()->setCreateButtonState(BookmarkView::CreateButtonState::CAN_CREATE);
getView<BookmarkView>()->update();
}
else
{
LOG_WARNING_STREAM(<< "No Bookmark to delete for active tokens.");
}
}
void BookmarkController::handleMessage(MessageEditBookmark* message)
{
LOG_INFO_STREAM(<< "Attempting to update Bookmark " << std::to_string(message->bookmarkId));
if (message->isEdge)
{
EdgeBookmark bookmark = m_storageAccess->getEdgeBookmarkById(message->bookmarkId);
bookmark.setDisplayName(message->displayName);
bookmark.setComment(message->comment);
BookmarkCategory category;
category.setName(message->categoryName);
bookmark.setCategory(category);
m_storageAccess->editEdgeBookmark(bookmark);
}
else
{
NodeBookmark bookmark = m_storageAccess->getNodeBookmarkById(message->bookmarkId);
bookmark.setDisplayName(message->displayName);
bookmark.setComment(message->comment);
BookmarkCategory category;
category.setName(message->categoryName);
bookmark.setCategory(category);
m_storageAccess->editNodeBookmark(bookmark);
}
getView<BookmarkView>()->update();
}
void BookmarkController::handleMessage(MessageFinishedParsing* message)
{
getView<BookmarkView>()->enableDisplayBookmarks(true);
}
std::vector<std::string> BookmarkController::getTokenNames(const std::vector<Id>& ids) const
{
std::vector<std::string> names;
for (unsigned int i = 0; i < ids.size(); i++)
{
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(ids[i]);
names.push_back(NameHierarchy::serialize(nameHierarchy));
}
return names;
}
std::vector<std::string> BookmarkController::getTokenDisplayNames(const std::vector<Id>& ids) const
{
std::vector<std::string> names;
for (unsigned int i = 0; i < ids.size(); i++)
{
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(ids[i]);
names.push_back(nameHierarchy.getRawName());
}
return names;
}
std::vector<int> BookmarkController::getTokenTypes(const std::vector<Id>& ids) const
{
std::vector<int> types;
for (unsigned int i = 0; i < ids.size(); i++)
{
int type = m_storageAccess->getNodeTypeForNodeWithId(ids[i]);
types.push_back(type);
}
return types;
}
std::string BookmarkController::getDisplayName(Id id) const
{
NameHierarchy nameHierarchy = m_storageAccess->getNameHierarchyForNodeWithId(id);
return nameHierarchy.getRawName();
}
BookmarkController::TempEdge BookmarkController::getEdge(const std::string& tokenName, const int tokenType) const
{
std::pair<std::string, std::string> edgeTokens = seperateEdgeToken(tokenName);
NameHierarchy source = NameHierarchy::deserialize(edgeTokens.first);
NameHierarchy target = NameHierarchy::deserialize(edgeTokens.second);
Id edgeId = m_storageAccess->getIdForEdge(Edge::intToType(tokenType), source, target);
TempEdge result;
result.edgeId = edgeId;
result.source = source;
result.target = target;
result.type = tokenType;
return result;
}
std::pair<std::string, std::string> BookmarkController::seperateEdgeToken(const std::string& token) const
{
std::pair<std::string, std::string> result;
if (token.find(m_edgeSeperatorToken) != std::string::npos)
{
std::vector<std::string> st = utility::splitToVector(token, m_edgeSeperatorToken);
if (st.size() != 2)
{
LOG_ERROR_STREAM(<< "Invalid edge token found: " << token);
return result;
}
else
{
result.first = st[0];
result.second = st[1];
}
}
return result;
}
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getFilteredBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkFilter& filter) const
{
std::vector<std::shared_ptr<Bookmark>> result;
if (filter == MessageDisplayBookmarks::BookmarkFilter::ALL)
{
return bookmarks;
}
else if (filter == MessageDisplayBookmarks::BookmarkFilter::NODES)
{
for (unsigned int i = 0; i < bookmarks.size(); i++)
{
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) == NULL)
{
result.push_back(bookmarks[i]);
}
}
return result;
}
else if (filter == MessageDisplayBookmarks::BookmarkFilter::EDGES)
{
for (unsigned int i = 0; i < bookmarks.size(); i++)
{
if (dynamic_cast<EdgeBookmark*>(bookmarks[i].get()) != NULL)
{
result.push_back(bookmarks[i]);
}
}
return result;
}
return result;
}
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkOrder& order) const
{
std::vector<std::shared_ptr<Bookmark>> result = bookmarks;
if (order == MessageDisplayBookmarks::BookmarkOrder::DATE_ASCENDING)
{
return getDateOrderedBookmarks(result, true);
}
else if (order == MessageDisplayBookmarks::BookmarkOrder::DATE_DESCENDING)
{
return getDateOrderedBookmarks(result, false);
}
else if (order == MessageDisplayBookmarks::BookmarkOrder::NAME_ASCENDING)
{
return getNameOrderedBookmarks(result, true);
}
else if (order == MessageDisplayBookmarks::BookmarkOrder::NAME_DESCENDING)
{
return getNameOrderedBookmarks(result, false);
}
return result;
}
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getDateOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const
{
std::vector<std::shared_ptr<Bookmark>> result = bookmarks;
std::sort(result.begin(), result.end(), BookmarkController::bookmarkDateCompare);
if (ascending == false)
{
std::reverse(result.begin(), result.end());
}
return result;
}
std::vector<std::shared_ptr<Bookmark>> BookmarkController::getNameOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const
{
std::vector<std::shared_ptr<Bookmark>> result = bookmarks;
std::sort(result.begin(), result.end(), BookmarkController::bookmarkNameCompare);
if (ascending == false)
{
std::reverse(result.begin(), result.end());
}
return result;
}
void BookmarkController::cleanBookmarkCategories()
{
std::vector<std::shared_ptr<Bookmark>> bookmarks = getAllBookmarks();
std::vector<BookmarkCategory> categories = getAllBookmarkCategories();
for (unsigned int i = 0; i < categories.size(); i++)
{
BookmarkCategory category = categories[i];
bool used = false;
for (unsigned int j = 0; j < bookmarks.size(); j++)
{
if (bookmarks[j]->getCategory().getName() == category.getName())
{
used = true;
break;
}
}
if (used == false)
{
m_storageAccess->removeBookmarkCategory(category.getId());
}
}
}
bool BookmarkController::bookmarkDateCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b)
{
return a->getTimeStamp() < b->getTimeStamp();
}
bool BookmarkController::bookmarkNameCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b)
{
std::string aName = a->getDisplayName();
std::string bName = b->getDisplayName();
aName = utility::toLowerCase(aName);
bName = utility::toLowerCase(bName);
unsigned int i = 0;
while (i < aName.length() && i < bName.length())
{
if (std::tolower(aName[i]) < std::tolower(bName[i]))
{
return true;
}
else if (std::tolower(aName[i]) > std::tolower(bName[i]))
{
return false;
}
++i;
}
return aName.length() < bName.length();
}
@@ -0,0 +1,104 @@
#ifndef BOOKMARK_CONTROLLER_H
#define BOOKMARK_CONTROLLER_H
#include "data/bookmark/Bookmark.h"
#include "data/name/NameHierarchy.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageActivateBookmark.h"
#include "utility/messaging/type/MessageActivateTokens.h"
#include "utility/messaging/type/MessageCreateBookmark.h"
#include "utility/messaging/type/MessageCreateBookmarkCategory.h"
#include "utility/messaging/type/MessageDeleteBookmark.h"
#include "utility/messaging/type/MessageDeleteBookmarkCategoryWithBookmarks.h"
#include "utility/messaging/type/MessageDeleteBookmarkForActiveTokens.h"
#include "utility/messaging/type/MessageDisplayBookmarks.h"
#include "utility/messaging/type/MessageEditBookmark.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "component/controller/Controller.h"
class StorageAccess;
class BookmarkController
: public Controller
, public MessageListener<MessageActivateBookmark>
, public MessageListener<MessageActivateTokens>
, public MessageListener<MessageCreateBookmark>
, public MessageListener<MessageCreateBookmarkCategory>
, public MessageListener<MessageDeleteBookmark>
, public MessageListener<MessageDeleteBookmarkCategoryWithBookmarks>
, public MessageListener<MessageDeleteBookmarkForActiveTokens>
, public MessageListener<MessageEditBookmark>
, public MessageListener<MessageFinishedParsing>
{
public:
BookmarkController(StorageAccess* storageAccess);
virtual ~BookmarkController();
virtual void clear();
std::vector<std::shared_ptr<Bookmark>> getAllBookmarks() const;
std::vector<std::shared_ptr<Bookmark>> getBookmarks(const MessageDisplayBookmarks::BookmarkFilter& filter, const MessageDisplayBookmarks::BookmarkOrder& order) const;
std::vector<std::string> getActiveTokenNames() const;
std::vector<std::string> getActiveTokenDisplayNames() const;
std::vector<BookmarkCategory> getAllBookmarkCategories() const;
bool activeTokenExists() const;
std::shared_ptr<Bookmark> getBookmarkForActiveToken() const; // or null if no bookmark for that token exists
private:
struct TempEdge
{
public:
Id edgeId;
NameHierarchy source;
NameHierarchy target;
int type;
};
virtual void handleMessage(MessageActivateBookmark* message);
virtual void handleMessage(MessageActivateTokens* message);
virtual void handleMessage(MessageCreateBookmark* message);
virtual void handleMessage(MessageCreateBookmarkCategory* message);
virtual void handleMessage(MessageDeleteBookmark* message);
virtual void handleMessage(MessageDeleteBookmarkCategoryWithBookmarks* message);
virtual void handleMessage(MessageDeleteBookmarkForActiveTokens* message);
virtual void handleMessage(MessageEditBookmark* message);
virtual void handleMessage(MessageFinishedParsing* message);
std::vector<std::string> getTokenNames(const std::vector<Id>& ids) const;
std::vector<std::string> getTokenDisplayNames(const std::vector<Id>& ids) const;
std::vector<int> getTokenTypes(const std::vector<Id>& ids) const;
std::string getDisplayName(Id id) const;
TempEdge getEdge(const std::string& tokenName, const int tokenType) const;
std::pair<std::string, std::string> seperateEdgeToken(const std::string& token) const;
std::vector<std::shared_ptr<Bookmark>> getFilteredBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkFilter& filter) const;
std::vector<std::shared_ptr<Bookmark>> getOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const MessageDisplayBookmarks::BookmarkOrder& order) const;
std::vector<std::shared_ptr<Bookmark>> getDateOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const;
std::vector<std::shared_ptr<Bookmark>> getNameOrderedBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks, const bool ascending) const;
void cleanBookmarkCategories();
static bool bookmarkDateCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b);
static bool bookmarkNameCompare(const std::shared_ptr<Bookmark> a, const std::shared_ptr<Bookmark> b);
static const std::string m_edgeSeperatorToken;
StorageAccess* m_storageAccess;
std::vector<Id> m_activeTokens;
std::vector<std::string> m_activeTokenNames;
std::vector<std::string> m_activeTokenDisplayNames;
std::vector<int> m_activeTokenTypes;
std::vector<Id> m_activeEdges;
std::vector<std::string> m_activeEdgeNames;
std::vector<std::string> m_activeEdgeDisplayNames;
std::vector<int> m_activeEdgeTypes;
bool m_activeTokenExists;
};
#endif // BOOKMARK_CONTROLLER_H
@@ -69,6 +69,11 @@ void IDECommunicationController::setEnabled(const bool enabled)
m_enabled = enabled;
}
void IDECommunicationController::sendInitialPing()
{
sendMessage(NetworkProtocolHelper::buildPingMessage());
}
void IDECommunicationController::handleSetActiveTokenMessage(
const NetworkProtocolHelper::SetActiveTokenMessage& message
)
@@ -175,6 +180,7 @@ void IDECommunicationController::handlePing(const NetworkProtocolHelper::PingMes
if (msg.ideId == "vs")
{
ideName = "Visual Studio";
msg.ideName = ideName;
}
// TODO: add the other ides
@@ -34,6 +34,9 @@ public:
bool getEnabled() const;
void setEnabled(const bool enabled);
protected:
void sendInitialPing();
private:
void handleSetActiveTokenMessage(const NetworkProtocolHelper::SetActiveTokenMessage& message);
void handleCreateProjectMessage(const NetworkProtocolHelper::CreateProjectMessage& message);
@@ -35,6 +35,14 @@ void StatusBarController::handleMessage(MessageFinishedParsing* message)
getView()->setErrorCount(errorCount);
}
void StatusBarController::handleMessage(MessagePingReceived* message)
{
std::string status = "Connected to ";
status += message->ideName;
getView()->showIdeStatus(status);
}
void StatusBarController::handleMessage(MessageRefresh* message)
{
getView()->setErrorCount(m_storageAccess->getErrorCount());
@@ -8,6 +8,7 @@
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageClearErrorCount.h"
#include "utility/messaging/type/MessageFinishedParsing.h"
#include "utility/messaging/type/MessagePingReceived.h"
#include "utility/messaging/type/MessageRefresh.h"
#include "utility/messaging/type/MessageShowErrors.h"
#include "utility/messaging/type/MessageStatus.h"
@@ -19,6 +20,7 @@ class StatusBarController
: public Controller
, public MessageListener<MessageClearErrorCount>
, public MessageListener<MessageFinishedParsing>
, public MessageListener<MessagePingReceived>
, public MessageListener<MessageRefresh>
, public MessageListener<MessageShowErrors>
, public MessageListener<MessageStatus>
@@ -34,6 +36,7 @@ public:
private:
virtual void handleMessage(MessageClearErrorCount* message);
virtual void handleMessage(MessageFinishedParsing* message);
virtual void handleMessage(MessagePingReceived* message);
virtual void handleMessage(MessageRefresh* message);
virtual void handleMessage(MessageShowErrors* message);
virtual void handleMessage(MessageStatus* message);
+85
View File
@@ -0,0 +1,85 @@
#include "component/view/BookmarkView.h"
#include "component/controller/BookmarkController.h"
BookmarkView::BookmarkView(ViewLayout* viewLayout)
: View(viewLayout)
, m_filter(MessageDisplayBookmarks::BookmarkFilter::ALL)
, m_order(MessageDisplayBookmarks::BookmarkOrder::DATE_DESCENDING)
{
}
BookmarkView::~BookmarkView()
{
}
std::string BookmarkView::getName() const
{
return "BookmarkView";
}
void BookmarkView::update()
{
if (bookmarkBrowserIsVisible())
{
displayBookmarks(getController()->getBookmarks(m_filter, m_order));
}
}
BookmarkController* BookmarkView::getController()
{
return View::getController<BookmarkController>();
}
void BookmarkView::handleMessage(MessageDisplayBookmarks* message)
{
if (bookmarkBrowserIsVisible() == true)
{
m_filter = message->filter;
m_order = message->order;
displayBookmarks(getController()->getBookmarks(message->filter, message->order));
}
displayBookmarks(getController()->getBookmarks(m_filter, m_order));
}
void BookmarkView::handleMessage(MessageDisplayBookmarkCreator* message)
{
std::vector<std::string> names = getController()->getActiveTokenDisplayNames();
if (getController()->activeTokenExists())
{
std::vector<BookmarkCategory> categories = getController()->getAllBookmarkCategories();
displayBookmarkEditor(getController()->getBookmarkForActiveToken(), categories);
}
else
{
for (unsigned int i = 0; i < names.size(); i++)
{
std::string name = names[i];
// skip the first letter as to not insert a leading space
for (unsigned int i = 1; i < name.size(); i++)
{
if (std::isupper(name[i]))
{
name.insert(i, 1, ' ');
i++;
}
}
names[i] = name;
}
displayBookmarkCreator(names, getController()->getAllBookmarkCategories());
}
}
void BookmarkView::handleMessage(MessageDisplayBookmarkEditor* message)
{
std::vector<BookmarkCategory> categories = getController()->getAllBookmarkCategories();
displayBookmarkEditor(message->bookmark, categories);
}
+56
View File
@@ -0,0 +1,56 @@
#ifndef BOOKMARK_VIEW_H
#define BOOKMARK_VIEW_H
#include "data/bookmark/Bookmark.h"
#include "component/view/View.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageDisplayBookmarks.h"
#include "utility/messaging/type/MessageDisplayBookmarkCreator.h"
#include "utility/messaging/type/MessageDisplayBookmarkEditor.h"
class BookmarkController;
class BookmarkView
: public View
, public MessageListener<MessageDisplayBookmarks>
, public MessageListener<MessageDisplayBookmarkCreator>
, public MessageListener<MessageDisplayBookmarkEditor>
{
public:
BookmarkView(ViewLayout* viewLayout);
virtual ~BookmarkView();
virtual std::string getName() const;
enum CreateButtonState
{
CAN_CREATE = 0,
CANNOT_CREATE,
ALREADY_CREATED
};
virtual void setCreateButtonState(const CreateButtonState& state) = 0;
virtual void enableDisplayBookmarks(bool enable) = 0;
virtual void update();
virtual bool bookmarkBrowserIsVisible() const = 0;
private:
BookmarkController* getController();
virtual void handleMessage(MessageDisplayBookmarks* message);
virtual void handleMessage(MessageDisplayBookmarkCreator* message);
virtual void handleMessage(MessageDisplayBookmarkEditor* message);
virtual void displayBookmarks(const std::vector<std::shared_ptr<Bookmark>>& bookmarks) = 0;
virtual void displayBookmarkCreator(const std::vector<std::string>& names, const std::vector<BookmarkCategory>& categories) = 0;
virtual void displayBookmarkEditor(std::shared_ptr<Bookmark> bookmark, const std::vector<BookmarkCategory>& categories) = 0;
MessageDisplayBookmarks::BookmarkFilter m_filter;
MessageDisplayBookmarks::BookmarkOrder m_order;
};
#endif // BOOKMARK_VIEW_H
+2
View File
@@ -16,6 +16,8 @@ public:
virtual void showMessage(const std::string& message, bool isError, bool showLoader) = 0;
virtual void setErrorCount(ErrorCountInfo errorCount) = 0;
virtual void showIdeStatus(const std::string& message) = 0;
protected:
StatusBarController* getController();
};
+2
View File
@@ -5,6 +5,7 @@
#include "component/view/CompositeView.h"
class BookmarkView;
class CodeView;
class DialogView;
class ErrorView;
@@ -31,6 +32,7 @@ public:
ViewLayout* viewLayout, CompositeView::CompositeDirection direction, const std::string& name) const = 0;
virtual std::shared_ptr<TabbedView> createTabbedView(ViewLayout* viewLayout, const std::string& name) const = 0;
virtual std::shared_ptr<BookmarkView> createBookmarkView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<ErrorView> createErrorView(ViewLayout* viewLayout) const = 0;
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const = 0;