2 * This file is part of NixNote/NeighborNote
\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 header().setStyleSheet("QHeaderView::section {border: 0.0em;}");
\r
49 setAcceptDrops(false);
\r
50 setDragEnabled(false);
\r
51 // setDragDropMode(QAbstractItemView.DragDropMode.DragDrop);
\r
52 setHeaderLabel(tr("Saved Searches"));
\r
53 setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);
\r
56 public void setEditAction(QAction e) {
\r
59 public void setDeleteAction(QAction d) {
\r
62 public void setAddAction(QAction a) {
\r
65 public void setIconAction(QAction a) {
\r
68 public void setIcons(HashMap<String, QIcon> i) {
\r
72 public void load(List<SavedSearch> tempList) {
\r
74 List<NTreeWidgetItem> index = new ArrayList<NTreeWidgetItem>();
\r
76 //Clear out the tree & reload
\r
78 String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
79 QIcon icon = new QIcon(iconPath+"search.png");
\r
81 for (int i=0; i<tempList.size(); i++) {
\r
82 search = tempList.get(i);
\r
83 NTreeWidgetItem child = new NTreeWidgetItem();
\r
84 child.setText(0, search.getName());
\r
85 if (icons != null && !icons.containsKey(search.getGuid())) {
\r
86 child.setIcon(0, icon);
\r
88 child.setIcon(0, icons.get(search.getGuid()));
\r
90 child.setText(1, search.getGuid());
\r
92 addTopLevelItem(child);
\r
94 sortItems(0, SortOrder.AscendingOrder);
\r
98 public boolean selectGuid(String guid) {
\r
99 QTreeWidgetItem root = invisibleRootItem();
\r
100 QTreeWidgetItem child;
\r
102 for (int i=0; i<root.childCount(); i++) {
\r
103 child = root.child(i);
\r
104 if (child.text(1).equals(guid)) {
\r
105 child.setSelected(true);
\r
114 public void contextMenuEvent(QContextMenuEvent event) {
\r
115 QMenu menu = new QMenu(this);
\r
116 menu.addAction(addAction);
\r
117 menu.addAction(editAction);
\r
118 menu.addAction(deleteAction);
\r
119 menu.addSeparator();
\r
120 menu.addAction(iconAction);
\r
121 menu.exec(event.globalPos());
\r
125 public void selectSavedSearch(QTreeWidgetItem item) {
\r
126 QTreeWidgetItem root = invisibleRootItem();
\r
127 QTreeWidgetItem child;
\r
129 for (int i=0; i<root.childCount(); i++) {
\r
130 child = root.child(i);
\r
131 if (child.text(1).equals(item.text(1))) {
\r
132 child.setSelected(true);
\r