2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.gui;
\r
22 import java.util.ArrayList;
\r
23 import java.util.HashMap;
\r
24 import java.util.List;
\r
26 import com.evernote.edam.type.SavedSearch;
\r
27 import com.trolltech.qt.core.Qt.SortOrder;
\r
28 import com.trolltech.qt.gui.QAbstractItemView;
\r
29 import com.trolltech.qt.gui.QAction;
\r
30 import com.trolltech.qt.gui.QContextMenuEvent;
\r
31 import com.trolltech.qt.gui.QIcon;
\r
32 import com.trolltech.qt.gui.QMenu;
\r
33 import com.trolltech.qt.gui.QTreeWidget;
\r
34 import com.trolltech.qt.gui.QTreeWidgetItem;
\r
36 public class SavedSearchTreeWidget extends QTreeWidget {
\r
37 private QAction editAction;
\r
38 private QAction deleteAction;
\r
39 private QAction addAction;
\r
40 private QAction iconAction;
\r
41 private HashMap<String, QIcon> icons;
\r
44 public SavedSearchTreeWidget() {
\r
45 // setAcceptDrops(true);
\r
46 // setDragEnabled(true);
\r
47 setProperty("hideTree", true);
\r
48 setAcceptDrops(false);
\r
49 setDragEnabled(false);
\r
50 // setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);
\r
51 setHeaderLabel(tr("Saved Searches"));
\r
52 setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);
\r
55 public void setEditAction(QAction e) {
\r
58 public void setDeleteAction(QAction d) {
\r
61 public void setAddAction(QAction a) {
\r
64 public void setIconAction(QAction a) {
\r
67 public void setIcons(HashMap<String, QIcon> i) {
\r
71 public void load(List<SavedSearch> tempList) {
\r
73 List<QTreeWidgetItem> index = new ArrayList<QTreeWidgetItem>();
\r
75 //Clear out the tree & reload
\r
77 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
78 QIcon icon = new QIcon(iconPath+"search.png");
\r
80 for (int i=0; i<tempList.size(); i++) {
\r
81 search = tempList.get(i);
\r
82 QTreeWidgetItem child = new QTreeWidgetItem();
\r
83 child.setText(0, search.getName());
\r
84 if (icons != null && !icons.containsKey(search.getGuid())) {
\r
85 child.setIcon(0, icon);
\r
87 child.setIcon(0, icons.get(search.getGuid()));
\r
89 child.setText(1, search.getGuid());
\r
91 addTopLevelItem(child);
\r
93 sortItems(0, SortOrder.AscendingOrder);
\r
97 public boolean selectGuid(String guid) {
\r
98 QTreeWidgetItem root = invisibleRootItem();
\r
99 QTreeWidgetItem child;
\r
101 for (int i=0; i<root.childCount(); i++) {
\r
102 child = root.child(i);
\r
103 if (child.text(1).equals(guid)) {
\r
104 child.setSelected(true);
\r
113 public void contextMenuEvent(QContextMenuEvent event) {
\r
114 QMenu menu = new QMenu(this);
\r
115 menu.addAction(addAction);
\r
116 menu.addAction(editAction);
\r
117 menu.addAction(deleteAction);
\r
118 menu.addSeparator();
\r
119 menu.addAction(iconAction);
\r
120 menu.exec(event.globalPos());
\r
124 public void selectSavedSearch(QTreeWidgetItem item) {
\r
125 QTreeWidgetItem root = invisibleRootItem();
\r
126 QTreeWidgetItem child;
\r
128 for (int i=0; i<root.childCount(); i++) {
\r
129 child = root.child(i);
\r
130 if (child.text(1).equals(item.text(1))) {
\r
131 child.setSelected(true);
\r