Enable the table selector in the DetailsView.
[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         private String tableName = "";
28
29         public DetailsPlace(String documentID, String tableName, String primarykey) {
30                 super(documentID);
31                 this.tableName = tableName;
32                 this.primaryKeyValue = primarykey;
33         }
34
35         public String getPrimaryKeyValue() {
36                 return primaryKeyValue;
37         }
38
39         public String getTableName() {
40                 return tableName;
41         }
42
43         @Prefix("details")
44         public static class Tokenizer implements PlaceTokenizer<DetailsPlace> {
45
46                 final String documentKey = "document=";
47                 final String tableKey = "table=";
48                 private final String primaryKeyValueKey = "value=";
49                 protected final String seperator = "&";
50
51                 @Override
52                 public String getToken(DetailsPlace place) {
53                         return documentKey + place.getDocumentID() + seperator + tableKey + place.getTableName() + seperator
54                                         + primaryKeyValueKey + place.getPrimaryKeyValue();
55                 }
56
57                 @Override
58                 public DetailsPlace getPlace(String token) {
59                         String[] tokenArray = token.split(seperator);
60
61                         if (tokenArray.length != 3)
62                                 return new DetailsPlace("", "", "");
63
64                         String documentID = "", tableName = "", primaryKeyValue = "";
65
66                         if (documentKey.equals(tokenArray[0].substring(0, documentKey.length()))) {
67                                 documentID = tokenArray[0].substring(documentKey.length());
68                         }
69
70                         if (tableKey.equals(tokenArray[1].substring(0, tableKey.length()))) {
71                                 tableName = tokenArray[1].substring(tableKey.length());
72                         }
73
74                         if (primaryKeyValueKey.equals(tokenArray[2].substring(0, primaryKeyValueKey.length()))) {
75                                 primaryKeyValue = tokenArray[2].substring(primaryKeyValueKey.length());
76                         }
77
78                         return new DetailsPlace(documentID, tableName, primaryKeyValue);
79                 }
80         }
81
82 }