1 | package com.gs3.testGXT.client.Keys;
|
---|
2 |
|
---|
3 | import java.util.Comparator;
|
---|
4 |
|
---|
5 | public class FileSystemKey implements Comparable<FileSystemKey> {
|
---|
6 | String key1; //path
|
---|
7 | String key2; //name
|
---|
8 |
|
---|
9 | String path; //actual path
|
---|
10 |
|
---|
11 | boolean folder = false; //indicator for if this item happens to be a folder
|
---|
12 | boolean walked = false; //indicator for if we've realized this nodes children yet
|
---|
13 | boolean droppable = true;
|
---|
14 |
|
---|
15 | public FileSystemKey(FileSystemKey k) {
|
---|
16 | this.key1 = k.key1;
|
---|
17 | this.key2 = k.key2;
|
---|
18 | this.folder = k.folder;
|
---|
19 | this.path = "";
|
---|
20 |
|
---|
21 | this.path = k.path;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public FileSystemKey(String key1, String key2, boolean folder, boolean walked) {
|
---|
25 | this.key1 = key1;
|
---|
26 | this.key2 = key2;
|
---|
27 | this.folder = folder;
|
---|
28 | this.path = key1 + "/" + key2;
|
---|
29 | this.walked = walked;
|
---|
30 | }
|
---|
31 |
|
---|
32 | //manually specify path, for the async method versions
|
---|
33 | public FileSystemKey(String key1, String key2, boolean folder, boolean walked, String path) {
|
---|
34 | this.key1 = key1;
|
---|
35 | this.key2 = key2;
|
---|
36 | this.folder = folder;
|
---|
37 | this.walked = walked;
|
---|
38 | this.path = path;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void SetKey(String k1, String k2, Boolean folder) {
|
---|
42 | if(k1 != null) {
|
---|
43 | this.key1 = k1;
|
---|
44 | }
|
---|
45 | if(k2 != null) {
|
---|
46 | this.key2 = k2;
|
---|
47 | }
|
---|
48 | if(folder != null) {
|
---|
49 | this.folder = folder;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public boolean Walked() {
|
---|
54 | return walked;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void setWalked() {
|
---|
58 | walked = true;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void Refresh() {
|
---|
62 | walked = false;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public String Key1() {
|
---|
66 | return key1;
|
---|
67 | }
|
---|
68 |
|
---|
69 | public String Key2() {
|
---|
70 | return key2;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public boolean isFolder() {
|
---|
74 | return folder;
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | //whether or not this is a folder is not included in the key or the hashcode,
|
---|
79 | //nor the string representation or comparator
|
---|
80 | @Override
|
---|
81 | public boolean equals(Object obj) {
|
---|
82 | if (obj == null) {
|
---|
83 | return false;
|
---|
84 | }
|
---|
85 | if (this.getClass().equals(obj.getClass())) {
|
---|
86 | final FileSystemKey other = (FileSystemKey) obj;
|
---|
87 | return key1.equals(other.key1) && key2.equals(other.key2);
|
---|
88 | } else {
|
---|
89 | return false;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Override
|
---|
94 | public int hashCode() {
|
---|
95 | int hash = 3;
|
---|
96 | hash = 53 * hash + (this.key1 != null ? this.key1.hashCode() : 0);
|
---|
97 | hash = 53 * hash + (this.key2 != null ? this.key2.hashCode() : 0);
|
---|
98 | return hash;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Gives the string representation for the item: ie, folder/file name
|
---|
103 | */
|
---|
104 | @Override
|
---|
105 | public String toString() {
|
---|
106 | return key2;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Gives the string representation of the item path (only useful for left-hand side) - Override for shortcuts
|
---|
111 | */
|
---|
112 | public String toPath() {
|
---|
113 | return this.path;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Gives the unique key for this item
|
---|
118 | */
|
---|
119 | public String toKey() {
|
---|
120 | return key1 + key2;
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Define whether or not the current item can be drag-dropped
|
---|
125 | */
|
---|
126 | public boolean Droppable() {
|
---|
127 | return droppable;
|
---|
128 | }
|
---|
129 |
|
---|
130 | @Override
|
---|
131 | public int compareTo(FileSystemKey o) {
|
---|
132 | int value = (key1 + "/" + key2).compareTo(o.key1 + "/" + o.key2);
|
---|
133 | //not sure if the magnitude of these values really matters at all
|
---|
134 | if(isFolder() && !o.isFolder())
|
---|
135 | return -100;
|
---|
136 | else if (o.isFolder() && !isFolder())
|
---|
137 | return 100;
|
---|
138 |
|
---|
139 | return value;
|
---|
140 | }
|
---|
141 |
|
---|
142 | public static Comparator<FileSystemKey> getComparator() {
|
---|
143 | return new Comparator<FileSystemKey>(){
|
---|
144 |
|
---|
145 | @Override
|
---|
146 | public int compare(FileSystemKey C1, FileSystemKey C2) {
|
---|
147 | return C1.compareTo(C2);
|
---|
148 | }
|
---|
149 | };
|
---|
150 | }
|
---|
151 | } |
---|