/v3.2/nimbits-tds/src/com/nimbits/client/panels/DiagramPropertyPanel.java
Java | 275 lines | 165 code | 74 blank | 36 comment | 10 complexity | 1e87d39727fbea7cbe6e4e89b90201f9 MD5 | raw file
1/* 2 * Copyright (c) 2010 Tonic Solutions LLC. 3 * 4 * http://www.nimbits.com 5 * 6 * 7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 8 * 9 * http://www.gnu.org/licenses/gpl.html 10 * 11 * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 12 */ 13 14package com.nimbits.client.panels; 15 16import com.extjs.gxt.ui.client.event.ButtonEvent; 17import com.extjs.gxt.ui.client.event.Listener; 18import com.extjs.gxt.ui.client.event.MessageBoxEvent; 19import com.extjs.gxt.ui.client.event.SelectionListener; 20import com.extjs.gxt.ui.client.widget.Html; 21import com.extjs.gxt.ui.client.widget.MessageBox; 22import com.extjs.gxt.ui.client.widget.VerticalPanel; 23import com.extjs.gxt.ui.client.widget.button.Button; 24import com.extjs.gxt.ui.client.widget.form.FormPanel; 25import com.extjs.gxt.ui.client.widget.form.Radio; 26import com.extjs.gxt.ui.client.widget.form.RadioGroup; 27import com.extjs.gxt.ui.client.widget.layout.FormData; 28import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; 29import com.google.gwt.core.client.GWT; 30import com.google.gwt.user.client.Element; 31import com.google.gwt.user.client.rpc.AsyncCallback; 32import com.google.gwt.user.client.ui.AbstractImagePrototype; 33import com.nimbits.client.exception.NimbitsException; 34import com.nimbits.client.icons.Icons; 35import com.nimbits.client.model.Const; 36import com.nimbits.client.model.diagram.Diagram; 37import com.nimbits.client.service.diagram.DiagramService; 38import com.nimbits.client.service.diagram.DiagramServiceAsync; 39 40 41/** 42 * Created by bsautner 43 * User: benjamin 44 * Date: 5/31/11 45 * Time: 1:05 PM 46 */ 47class DiagramPropertyPanel extends NavigationEventProvider { 48 49 private final Diagram diagram; 50 51 // private final Icons ICONS = GWT.create(Icons.class); 52 private final boolean readOnly; 53 private final RadioGroup radioGroup = new RadioGroup(); 54 private final Radio radioProtection0 = new Radio(); 55 private final Radio radioProtection1 = new Radio(); 56 private final Radio radioProtection2 = new Radio(); 57// public interface DiagramDeletedListener { 58// public void onDiagramDeleted(Diagram p); 59// 60// } 61// private List<DiagramDeletedListener> diagramDeletedListeners = new ArrayList<DiagramDeletedListener>(); 62// public void addDiagramDeletedListeners(DiagramDeletedListener listener) { 63// diagramDeletedListeners.add(listener); 64// } 65// 66// private void notifyDiagramDeletedListener(Diagram p) { 67// for (DiagramDeletedListener DiagramDeletedListener : diagramDeletedListeners) { 68// DiagramDeletedListener.onDiagramDeleted(p); 69// } 70// } 71 72 73 DiagramPropertyPanel(final Diagram d, final boolean readOnly) { 74 this.diagram = d; 75 this.readOnly = readOnly; 76 } 77 78 private VerticalPanel vp; 79 80 private FormData formData; 81 82 @Override 83 protected void onRender(final Element parent, final int index) { 84 super.onRender(parent, index); 85 formData = new FormData("-20"); 86 vp = new VerticalPanel(); 87 ToolBar mainToolBar = mainToolBar(); 88 vp.add(mainToolBar); 89 vp.setSpacing(10); 90 createForm(); 91 92 add(vp); 93 } 94 95 private void createForm() { 96 FormPanel simple = new FormPanel(); 97 98 simple.setHeaderVisible(false); 99 simple.setFrame(false); 100 simple.setWidth(480); 101 102 103 radioProtection0.setBoxLabel("Only Me"); 104 radioProtection0.setValue((diagram.getProtectionLevel() == 0)); 105 106 107 radioProtection1.setBoxLabel("My Connections"); 108 radioProtection1.setValue((diagram.getProtectionLevel() == 1)); 109 110 111 radioProtection2.setBoxLabel("Anyone"); 112 radioProtection2.setValue((diagram.getProtectionLevel() == 2)); 113 114 115 radioGroup.setFieldLabel("Who can view"); 116 117 radioGroup.add(radioProtection0); 118 radioGroup.add(radioProtection1); 119 radioGroup.add(radioProtection2); 120 simple.add(radioGroup, formData); 121 122 123 String url = "http://" + com.google.gwt.user.client.Window.Location.getHostName() + "?" + Const.PARAM_DIAGRAM + "=" + diagram.getUuid(); 124 125 if (com.google.gwt.user.client.Window.Location.getHostName().equals("127.0.0.1")) { 126 url = "http://127.0.0.1:8888/nimbits.html?gwt.codesvr=127.0.0.1:9997&" + Const.PARAM_DIAGRAM + "=" + diagram.getUuid(); 127 } 128 129 Html h = new Html("<p>This diagram can be viewed in a full window by anyone by setting" + 130 " the protection level below and sharing this url:</p><br>" + 131 " <A href =\"" + url + "\">" + url + "</a>"); 132 vp.add(h); 133 134 135 vp.add(simple); 136 } 137 138 ToolBar mainToolBar() { 139 ToolBar toolBar = new ToolBar(); 140 toolBar.setHeight(""); 141 142 143 final Button buttonDelete = createDeleteButton(); 144 final Button buttonUpdate = createUpdateButton(); 145 146 final Button buttonSave = new Button("Save"); 147 148 buttonSave.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.SaveAll())); 149 buttonSave.addSelectionListener(new SelectionListener<ButtonEvent>() { 150 public void componentSelected(ButtonEvent ce) { 151 152 try { 153 saveDiagram(); 154 } catch (NimbitsException ignored) { 155 156 } 157 } 158 }); 159 160 161 toolBar.add(buttonSave); 162 163 toolBar.add(buttonUpdate); 164 165 toolBar.add(buttonDelete); 166 // buttonDelete.setWidth("90px"); 167 168 169 return toolBar; 170 171 172 } 173 174 private Button createDeleteButton() { 175 final Button buttonDelete = new Button("Delete"); 176 177 buttonDelete.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.delete())); 178 final DiagramServiceAsync diagramService = GWT.create(DiagramService.class); 179 180 final Listener<MessageBoxEvent> deleteDiagramListener = new Listener<MessageBoxEvent>() { 181 public void handleEvent(MessageBoxEvent ce) { 182 Button btn = ce.getButtonClicked(); 183 184 if (btn.getText().equals("Yes")) { 185 diagramService.deleteDiagram(diagram, new AsyncCallback<Void>() { 186 187 @Override 188 public void onFailure(Throwable caught) { 189 190 191 } 192 193 @Override 194 public void onSuccess(Void result) { 195 try { 196 notifyDiagramDeletedListener(diagram, readOnly); 197 } catch (NimbitsException e) { 198 199 } 200 201 202 } 203 204 }); 205 206 } 207 208 } 209 }; 210 buttonDelete.addSelectionListener(new SelectionListener<ButtonEvent>() { 211 public void componentSelected(ButtonEvent ce) { 212 213 MessageBox.confirm("Confirm", "Are you sure you want delete this diagram?", deleteDiagramListener); 214 } 215 }); 216 return buttonDelete; 217 } 218 219 private Button createUpdateButton() { 220 final Button buttonUpdate = new Button("Update"); 221 buttonUpdate.setIcon(AbstractImagePrototype.create(Icons.INSTANCE.album())); 222 223 buttonUpdate.addSelectionListener(new SelectionListener<ButtonEvent>() { 224 public void componentSelected(ButtonEvent ce) { 225 226 final com.extjs.gxt.ui.client.widget.Window w = new com.extjs.gxt.ui.client.widget.Window(); 227 w.setAutoWidth(true); 228 w.setHeading("Upload a process diagram in .svg format"); 229 final DiagramUploadPanel p = new DiagramUploadPanel(DiagramUploadPanel.UploadType.updatedFile, diagram); 230 p.addDiagramAddedListeners(new DiagramUploadPanel.DiagramAddedListener() { 231 @Override 232 public void onDiagramAdded() { 233 234 w.hide(); 235 // notifyDiagramClickedListener(); 236 // reloadTree(); 237 } 238 }); 239 240 w.add(p); 241 w.show(); 242 } 243 }); 244 return buttonUpdate; 245 } 246 247 private void saveDiagram() throws NimbitsException { 248 249 final DiagramServiceAsync serviceAsync = GWT.create(DiagramService.class); 250 if (radioProtection0.getValue()) { 251 diagram.setProtectionLevel(0); 252 } else if (radioProtection1.getValue()) { 253 diagram.setProtectionLevel(1); 254 } else if (radioProtection2.getValue()) { 255 diagram.setProtectionLevel(2); 256 } 257 258 259 serviceAsync.updateDiagram(diagram, new AsyncCallback<Diagram>() { 260 261 @Override 262 public void onFailure(Throwable throwable) { 263 264 } 265 266 @Override 267 public void onSuccess(Diagram diagram) { 268 MessageBox.info("Diagram Settings", "Diagram Updated", null); 269 270 } 271 }); 272 273 274 } 275}