Use primaryKeyValue naming convention in constructor of DetailsPlace.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / client / place / DetailsPlace.java
1 /*
2  * Copyright (C) 2011 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
6  * GWT-Glom is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with GWT-Glom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package org.glom.web.client.place;
21
22 import com.google.gwt.place.shared.PlaceTokenizer;
23 import com.google.gwt.place.shared.Prefix;
24
25 public class DetailsPlace extends HasSelectableTablePlace {
26         private String primaryKeyValue = "";
27
28         public DetailsPlace(String documentID, String tableName, String primarykeyValue) {
29                 super(documentID, tableName);
30                 this.primaryKeyValue = primarykeyValue;
31         }
32
33         public String getPrimaryKeyValue() {
34                 return primaryKeyValue;
35         }
36
37         @Prefix("details")
38         public static class Tokenizer extends HasSelectableTablePlace.Tokenizer implements PlaceTokenizer<DetailsPlace> {
39
40                 private final String primaryKeyValueKey = "value=";
41
42                 @Override
43                 public String getToken(DetailsPlace place) {
44                         return documentKey + place.getDocumentID() + seperator + tableKey + place.getTableName() + seperator
45                                         + primaryKeyValueKey + place.getPrimaryKeyValue();
46                 }
47
48                 @Override
49                 public DetailsPlace getPlace(String token) {
50                         String[] tokenArray = token.split(seperator);
51
52                         if (tokenArray.length != 3)
53                                 return new DetailsPlace("", "", "");
54
55                         String documentID = "", tableName = "", primaryKeyValue = "";
56
57                         if (documentKey.equals(tokenArray[0].substring(0, documentKey.length()))) {
58                                 documentID = tokenArray[0].substring(documentKey.length());
59                         }
60
61                         if (tableKey.equals(tokenArray[1].substring(0, tableKey.length()))) {
62                                 tableName = tokenArray[1].substring(tableKey.length());
63                         }
64
65                         if (primaryKeyValueKey.equals(tokenArray[2].substring(0, primaryKeyValueKey.length()))) {
66                                 primaryKeyValue = tokenArray[2].substring(primaryKeyValueKey.length());
67                         }
68
69                         return new DetailsPlace(documentID, tableName, primaryKeyValue);
70                 }
71         }
72
73 }