Author: bbrossaud Date: 2010-06-29 15:33:59 +0200 (Tue, 29 Jun 2010) New Revision: 167 Url: http://nuiton.org/repositories/revision/wikitty/167 Log: remove bugs Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Data.java trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java trunk/wikitty-ui-zk/src/main/webapp/index.zul trunk/wikitty-ui-zk/src/main/webapp/wikitty.zul Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Data.java =================================================================== --- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Data.java 2010-06-29 13:14:14 UTC (rev 166) +++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/Data.java 2010-06-29 13:33:59 UTC (rev 167) @@ -95,6 +95,16 @@ _driver = driver; } + public void setAll(String name, String db, String driver, String solr, String url, String login, String password) { + setName(name); + setDb(db); + setDriver(driver); + setSolr(solr); + setURL(url); + setLogin(login); + setPassword(password); + } + /* * Getters */ Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java =================================================================== --- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java 2010-06-29 13:14:14 UTC (rev 166) +++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/LoginController.java 2010-06-29 13:33:59 UTC (rev 167) @@ -22,6 +22,7 @@ import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Sessions; import org.zkoss.zk.ui.util.GenericForwardComposer; +import org.zkoss.zul.Button; import org.zkoss.zul.Combobox; import org.zkoss.zul.Comboitem; import org.zkoss.zul.Groupbox; @@ -45,7 +46,6 @@ protected Listbox dataList; protected ApplicationConfig _config = new ApplicationConfig(); protected Properties _properties = new Properties(); - protected Window win; public LoginController() throws IOException { initConfig(); @@ -60,6 +60,7 @@ Window window = (Window) comp; Groupbox box = (Groupbox) window.getFellow("loginPassword"); box.setVisible(false); + disableUpdateButtons(); } public void initConfig() { @@ -71,6 +72,31 @@ } } + protected void disableUpdateButtons() { + Button update = (Button) self.getFellow("update"); + if (update.isDisabled() == false) { + update.setDisabled(true); + } + update = (Button) self.getFellow("distantUpdate"); + if (!update.isDisabled()) { + update.setDisabled(true); + } + } + + protected void enableLocalUpdateButton() { + Button update = (Button) self.getFellow("update"); + if (update.isDisabled()) { + update.setDisabled(false); + } + } + + protected void enableDistantUpdateButton() { + Button update = (Button) self.getFellow("distantUpdate"); + if (update.isDisabled()) { + update.setDisabled(false); + } + } + protected void saveNewData(Data data) throws FileNotFoundException, IOException { String name = ""; String path = ""; @@ -106,6 +132,29 @@ createProxyDatas(); } + protected void saveUpdateData(Data data) throws IOException { + String path = data.getPath(); + _properties.setProperty(path + ".name", data.getName()); + String db = data.getDb(); + if (!db.isEmpty()) { + _properties.setProperty(path + ".db", db); + } + String driver = data.getDriver(); + if (!driver.isEmpty()) { + _properties.setProperty(path + ".driver", driver); + } + String solr = data.getSolr(); + if (!solr.isEmpty()) { + _properties.setProperty(path + ".solr", solr); + } + String url = data.getUrl(); + if (!url.isEmpty()) { + _properties.setProperty(path + ".url", url); + } + saveProperties(); + createProxyDatas(); + } + protected void loadProperties() throws IOException { String filePath = _config.getOption("wikitty-ui-zk.filePath"); File file = new File(filePath); @@ -174,11 +223,15 @@ } } - protected WikittyProxy createProxy(Properties properties, String login, String password) { + protected WikittyProxy createLocalProxy(Properties properties, String login, String password) { WikittyProxy proxy = new WikittyProxy(); - WikittyService ws = new WikittyServiceJDBC(properties); - ws = new WikittyServiceCached(ws); - proxy.setWikittyService(ws); + try { + WikittyService ws = new WikittyServiceJDBC(properties); + ws = new WikittyServiceCached(ws); + proxy.setWikittyService(ws); + } catch (Exception eee) { + return null; + } if (!login.isEmpty()) { proxy.login(login, password); } @@ -193,25 +246,54 @@ protected void fillDistantProxy(Data data) { ((Textbox) this.self.getFellow("distantName")).setValue(data.getName()); ((Textbox) this.self.getFellow("distantURL")).setValue(data.getUrl()); + enableDistantUpdateButton(); } protected void fillLocalProxy(Data data) { - ((Textbox) this.self.getFellow("Name")).setValue(data.getName()); - ((Textbox) this.self.getFellow("Solr")).setValue(data.getSolr()); - ((Textbox) this.self.getFellow("Db")).setValue(data.getDb()); + ((Textbox) this.self.getFellow("name")).setValue(data.getName()); + ((Textbox) this.self.getFellow("solr")).setValue(data.getSolr()); + ((Textbox) this.self.getFellow("db")).setValue(data.getDb()); ((Combobox) this.self.getFellow("driver")).setValue(data.getDriver()); + enableLocalUpdateButton(); } + protected void clearAllLocalFields() { + Textbox input = (Textbox) self.getFellow("name"); + input.setValue(""); + input = (Textbox) self.getFellow("solr"); + input.setValue(""); + input = (Textbox) self.getFellow("db"); + input.setValue(""); + input = (Textbox) self.getFellow("login"); + input.setValue(""); + input = (Textbox) self.getFellow("password"); + input.setValue(""); + Combobox box = (Combobox) self.getFellow("driver"); + box.setText(null); + } + + protected void clearAllDistantFields() { + Textbox input = (Textbox) self.getFellow("distantName"); + input.setValue(""); + input = (Textbox) self.getFellow("distantURL"); + input.setValue(""); + input = (Textbox) self.getFellow("distantLogin"); + input.setValue(""); + input = (Textbox) self.getFellow("distantPassword"); + input.setValue(""); + } + /* * Events */ public void onSelect$dataList() { Listitem item = dataList.getSelectedItem(); if (item != null) { + disableUpdateButtons(); Data data = (Data) item.getValue(); String login = data.getLogin(); String password = data.getPassword(); - Groupbox box = (Groupbox) win.getFellow("loginPassword"); + Groupbox box = (Groupbox) this.self.getFellow("loginPassword"); if (box != null) { if (!password.isEmpty() && !login.isEmpty()) { box.setVisible(true); @@ -223,6 +305,8 @@ box.setVisible(false); } } + clearAllDistantFields(); + clearAllLocalFields(); } } @@ -239,39 +323,71 @@ } } + public void onClick$update() throws IOException { + Listitem item = dataList.getSelectedItem(); + if (item != null) { + Data data = (Data) item.getValue(); + String name = ((Textbox) this.self.getFellow("name")).getValue(); + String db = ((Textbox) this.self.getFellow("db")).getValue(); + String solr = ((Textbox) this.self.getFellow("solr")).getValue(); + Combobox box = (Combobox) this.self.getFellow("driver"); + String driver = ""; + Comboitem boit = box.getSelectedItem(); + if (boit != null) { + driver = boit.getLabel(); + } + if (!name.isEmpty() && !db.isEmpty() && !solr.isEmpty() && !driver.isEmpty()) { + data.setAll(name, db, driver, solr, null, data.getLogin(), data.getPassword()); + saveUpdateData(data); + disableUpdateButtons(); + } + } + } + + public void onClick$distantUpdate() throws IOException { + Listitem item = dataList.getSelectedItem(); + if (item != null) { + Data data = (Data) item.getValue(); + String name = ((Textbox) this.self.getFellow("distantName")).getValue(); + String URL = ((Textbox) this.self.getFellow("distantURL")).getValue(); + if (!name.isEmpty() && !URL.isEmpty()) { + data.setAll(name, null, null, null, URL, data.getLogin(), data.getPassword()); + saveUpdateData(data); + disableUpdateButtons(); + } + } + } + public void onClick$select() throws ArgumentsParserException { Listitem item = dataList.getSelectedItem(); if (item != null) { Data data = (Data) item.getValue(); - String login = ((Textbox) win.getFellow("selectLogin")).getValue(); - String password = ((Textbox) win.getFellow("selectPassword")).getValue(); + String login = ((Textbox) this.self.getFellow("selectLogin")).getValue(); + String password = ((Textbox) this.self.getFellow("selectPassword")).getValue(); if (data.hasLoginPassword()) { if (!login.equals(data.getLogin()) || !password.equals(password)) { return; } } - ApplicationConfig config = new ApplicationConfig(); - config.parse(new String[]{}); - Properties properties = config.getFlatOptions(); - properties.setProperty("solr.data.dir", data.getSolr()); - properties.setProperty("jdbc.con.driver", data.getDriver()); - properties.setProperty("jdbc.con.host", data.getDb()); - properties.setProperty("jdbc.con.userName", "sa"); - properties.setProperty("jdbc.con.password", ""); - System.setProperty("solr.data.dir", data.getSolr()); - WikittyProxy proxy = createProxy(properties, login, password); - goToWikittyPage(proxy); + WikittyProxy proxy = null; + if (data.getUrl().isEmpty()) { + Properties properties = getLocalProperties(data); + proxy = createLocalProxy(properties, login, password); + } + if (proxy != null) { + goToWikittyPage(proxy); + } } } public void onClick$add() throws FileNotFoundException, IOException { - String name = ((Textbox) win.getFellow("Name")).getValue(); - String db = ((Textbox) win.getFellow("Db")).getValue(); - String solr = ((Textbox) win.getFellow("Solr")).getValue(); - String login = ((Textbox) win.getFellow("Login")).getValue(); - String password = ((Textbox) win.getFellow("Password")).getValue(); + String name = ((Textbox) this.self.getFellow("name")).getValue(); + String db = ((Textbox) this.self.getFellow("db")).getValue(); + String solr = ((Textbox) this.self.getFellow("solr")).getValue(); + String login = ((Textbox) this.self.getFellow("login")).getValue(); + String password = ((Textbox) this.self.getFellow("password")).getValue(); String driver = ""; - Combobox box = (Combobox) win.getFellow("driver"); + Combobox box = (Combobox) this.self.getFellow("driver"); Comboitem item = box.getSelectedItem(); if (item != null) { driver = item.getLabel(); @@ -282,6 +398,17 @@ } } + public void onClick$distantAdd() throws FileNotFoundException, IOException { + String name = ((Textbox) this.self.getFellow("distantName")).getValue(); + String URL = ((Textbox) this.self.getFellow("distantURL")).getValue(); + String login = ((Textbox) this.self.getFellow("distantLogin")).getValue(); + String password = ((Textbox) this.self.getFellow("distantPassword")).getValue(); + if (!name.isEmpty() && !URL.isEmpty()) { + Data data = new Data(name, null, null, null, URL, login, password); + saveNewData(data); + } + } + public void onClick$delete() throws IOException { Set<Listitem> set = dataList.getSelectedItems(); List<Listitem> items = new ArrayList<Listitem>(set); @@ -292,6 +419,7 @@ _proxyModel.removeData(data); } saveProperties(); + disableUpdateButtons(); } } @@ -304,10 +432,15 @@ @Override public void render(Listitem item, Object data) throws Exception { item.setValue(data); - item.setLabel(((Data) data).getName()); + String proxyName = ((Data) data).getName(); + if (!((Data) data).getUrl().isEmpty()) { + proxyName += " (Distant)"; + } + item.setLabel(proxyName); } }; } + /* * Setters */ @@ -318,4 +451,17 @@ public ProxyModel getProxyModel() { return _proxyModel; } + + public Properties getLocalProperties(Data data) throws ArgumentsParserException { + ApplicationConfig config = new ApplicationConfig(); + config.parse(new String[]{}); + Properties properties = config.getFlatOptions(); + properties.setProperty("solr.data.dir", data.getSolr()); + properties.setProperty("jdbc.con.driver", data.getDriver()); + properties.setProperty("jdbc.con.host", data.getDb()); + properties.setProperty("jdbc.con.userName", "sa"); + properties.setProperty("jdbc.con.password", ""); + System.setProperty("solr.data.dir", data.getSolr()); + return properties; + } } Modified: trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java =================================================================== --- trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java 2010-06-29 13:14:14 UTC (rev 166) +++ trunk/wikitty-ui-zk/src/main/java/org/nuiton/wikitty/ui/WikittyController.java 2010-06-29 13:33:59 UTC (rev 167) @@ -14,6 +14,7 @@ import org.nuiton.wikitty.Wikitty; import org.nuiton.wikitty.WikittyExtension; import org.nuiton.wikitty.WikittyProxy; +import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Button; @@ -24,6 +25,7 @@ import org.zkoss.zul.Listitem; import org.zkoss.zul.ListitemRenderer; import org.zkoss.zul.Textbox; +import org.zkoss.zul.Window; /** * @@ -43,13 +45,32 @@ public WikittyController() { HttpSession Session = (HttpSession) Executions.getCurrent().getDesktop().getSession().getNativeSession(); WikittyProxy proxy = (WikittyProxy) Session.getAttribute("proxy"); - _model = new Model(proxy.getWikittyService()); - _extensions = _model.retrieveWikittyExtensions(); + if (proxy != null) { + _model = new Model(proxy.getWikittyService()); + _extensions = _model.retrieveWikittyExtensions(); + } else { + Executions.sendRedirect("/"); + } } + @Override + public void doAfterCompose(Component comp) throws Exception { + super.doAfterCompose(comp); + + Window window = (Window) comp; + Button add = (Button) window.getFellow("addNewInput"); + add.setDisabled(true); + Button delete = (Button) window.getFellow("deleteInput"); + delete.setDisabled(true); + } + /* * Events */ + public void onClick$home() { + Executions.sendRedirect("/"); + } + public void onOK$Search() { Textbox textbox = (Textbox) self.getFellow("Search"); String search = textbox.getValue(); @@ -173,6 +194,11 @@ _wikittyForm.setHoldExtensions(current); List<Wikitty> list = _model.retrieveWikittiesByExtensionName(current.getName()); _wikittyModel.setWikitties(list); + Window window = (Window) this.self; + Button add = (Button) window.getFellow("addNewInput"); + add.setDisabled(true); + Button delete = (Button) window.getFellow("deleteInput"); + delete.setDisabled(true); } public void setSelectedNewExtension(WikittyExtension current) { Modified: trunk/wikitty-ui-zk/src/main/webapp/index.zul =================================================================== --- trunk/wikitty-ui-zk/src/main/webapp/index.zul 2010-06-29 13:14:14 UTC (rev 166) +++ trunk/wikitty-ui-zk/src/main/webapp/index.zul 2010-06-29 13:33:59 UTC (rev 167) @@ -20,26 +20,28 @@ <button id="delete" label="Delete" width="36px" height="24px" /> <button id="modify" label="Modify" width="36px" height="24px" /> </groupbox> + <groupbox> <vbox> <label value="Name" /> - <textbox id="Name"/> + <textbox id="name"/> <label value="DB" /> - <textbox id="Db" /> + <textbox id="db" /> <combobox id="driver"> <comboitem label="org.h2.Driver" /> <comboitem label="mySQL" /> </combobox> <label value="Solr" /> - <textbox id="Solr" /> + <textbox id="solr" /> </vbox> <vbox> <label value="Login" /> - <textbox id="Login" /> + <textbox id="login" /> <label value="Password" /> - <textbox id="Password" /> + <textbox id="password" /> </vbox> <button id="add" label="Add" width="36px" height="24px" /> + <button id="update" label="Update" width="36px" height="24px" /> </groupbox> <groupbox> @@ -54,6 +56,7 @@ <textbox id="distantPassword" /> </vbox> <button id="distantAdd" label="Add" width="36px" height="24px" /> + <button id="distantUpdate" label="Update" width="36px" height="24px" /> </groupbox> </window> \ No newline at end of file Modified: trunk/wikitty-ui-zk/src/main/webapp/wikitty.zul =================================================================== --- trunk/wikitty-ui-zk/src/main/webapp/wikitty.zul 2010-06-29 13:14:14 UTC (rev 166) +++ trunk/wikitty-ui-zk/src/main/webapp/wikitty.zul 2010-06-29 13:33:59 UTC (rev 167) @@ -1,8 +1,9 @@ <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?> -<window id="win" title="To do list" width="800px" border="normal" apply="org.nuiton.wikitty.ui.WikittyController"> +<window id="win" title="wikitty" width="800px" border="normal" apply="org.nuiton.wikitty.ui.WikittyController"> Search: <textbox id="Search" /> + <toolbarbutton id="home" label="Select another proxy"/> <listbox id="extensionListBox" multiple="true" rows="8" model="@{win$composer.extensions}" selectedItem="@{win$composer.selectedExtension}">