Revision 87487bbf

b/src/gr/grnet/pithos/web/client/Const.java
36 36
    public static final String COMMA = ",";
37 37
    public static final String TILDE = "~";
38 38
    public static final String SEMI = ";";
39
    public static final String COLON = ":";
39 40
    public static final String QUESTION_MARK = "?";
40 41
    public static final String AMPERSAND = "&";
41 42

  
......
45 46
    public static final String UPDATE_EQ = "update=";
46 47
    public static final String QUESTION_MARK_UPDATE_EQ = QUESTION_MARK + UPDATE_EQ;
47 48

  
49
    public static final String HTML_NBSP = " ";
50

  
48 51

  
49 52
    public static final String NL = "\n";
50 53

  
......
56 59
    public static String PurgeContainer(String name) {
57 60
        return "Purge Container [" + name + "]";
58 61
    }
62

  
63
    public static String inSpan(String html) {
64
        return "<span>" + html + "</span>";
65
    }
66

  
67
    public static String inSpan(String html0, String html1, String ...html) {
68
        final int knownLength = html0.length() + html1.length();
69
        final int estimatedLength = knownLength * html.length;
70
        final StringBuilder sb = new StringBuilder(estimatedLength);
71
        sb.append(html0);
72
        sb.append(html1);
73
        for(String s : html) {
74
            sb.append(s);
75
        }
76

  
77
        return inSpan(sb.toString());
78
    }
59 79
}
b/src/gr/grnet/pithos/web/client/FolderPermissionsDialog.java
34 34
 */
35 35
package gr.grnet.pithos.web.client;
36 36

  
37
import gr.grnet.pithos.web.client.foldertree.Folder;
38
import gr.grnet.pithos.web.client.rest.PostRequest;
39
import gr.grnet.pithos.web.client.rest.PutRequest;
40
import gr.grnet.pithos.web.client.rest.RestException;
41

  
42
import java.util.Map;
43

  
44 37
import com.google.gwt.core.client.GWT;
45 38
import com.google.gwt.core.client.Scheduler;
46 39
import com.google.gwt.dom.client.NativeEvent;
......
52 45
import com.google.gwt.http.client.URL;
53 46
import com.google.gwt.user.client.Command;
54 47
import com.google.gwt.user.client.Event.NativePreviewEvent;
55
import com.google.gwt.user.client.ui.Anchor;
56
import com.google.gwt.user.client.ui.Button;
57
import com.google.gwt.user.client.ui.DialogBox;
58
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
59
import com.google.gwt.user.client.ui.HorizontalPanel;
60
import com.google.gwt.user.client.ui.Label;
61
import com.google.gwt.user.client.ui.VerticalPanel;
48
import com.google.gwt.user.client.ui.*;
49
import gr.grnet.pithos.web.client.foldertree.Folder;
50
import gr.grnet.pithos.web.client.rest.PostRequest;
51
import gr.grnet.pithos.web.client.rest.PutRequest;
52
import gr.grnet.pithos.web.client.rest.RestException;
53

  
54
import java.util.Map;
62 55

  
63 56
/**
64 57
 * The 'Folder properties' dialog box implementation.
......
67 60

  
68 61
    protected Pithos app;
69 62

  
70
	/**
71
	 * The widget that holds the folderName of the folder.
72
	 */
73
	Label folderName = new Label();
63
    /**
64
     * The widget that holds the folderName of the folder.
65
     */
66
    Label folderName = new Label();
67

  
68
    protected PermissionsList permList;
69

  
70
    final Folder folder;
74 71

  
75
	protected PermissionsList permList;
72
    final VerticalPanel inner;
76 73

  
77
	final Folder folder;
74
    final Button updateButton;
78 75

  
79
	final VerticalPanel inner;
76
    private boolean _initialPermissionCheck = true;
80 77

  
81
	/**
82
	 * The widget's constructor.
83
	 */
84
	public FolderPermissionsDialog(final Pithos app, Folder selected) {
78
    /**
79
     * The widget's constructor.
80
     */
81
    public FolderPermissionsDialog(final Pithos app, Folder selected) {
85 82
        this.app = app;
86
		Anchor close = new Anchor("close");
87
		close.addStyleName("close");
88
		close.addClickHandler(new ClickHandler() {
89
			
90
			@Override
91
			public void onClick(ClickEvent event) {
92
				hide();
93
			}
94
		});
83
        Anchor close = new Anchor("close");
84
        close.addStyleName("close");
85
        close.addClickHandler(new ClickHandler() {
95 86

  
96
		setGlassEnabled(true);
97
		setStyleName("pithos-DialogBox");
87
            @Override
88
            public void onClick(ClickEvent event) {
89
                hide();
90
            }
91
        });
98 92

  
99
		// Enable IE selection for the dialog (must disable it upon closing it)
100
		Pithos.enableIESelection();
93
        setGlassEnabled(true);
94
        setStyleName("pithos-DialogBox");
101 95

  
102
		folder = selected;
96
        // Enable IE selection for the dialog (must disable it upon closing it)
97
        Pithos.enableIESelection();
103 98

  
104
		setText("Folder permissions");
99
        folder = selected;
105 100

  
106
		// Outer contains inner and buttons
107
		VerticalPanel outer = new VerticalPanel();
108
		outer.add(close);
109
		// Inner contains generalPanel and permPanel
110
		inner = new VerticalPanel();
111
		inner.addStyleName("inner");
101
        setText("Folder permissions");
112 102

  
103
        // Outer contains inner and buttons
104
        VerticalPanel outer = new VerticalPanel();
105
        outer.add(close);
106
        // Inner contains generalPanel and permPanel
107
        inner = new VerticalPanel();
108
        inner.addStyleName("inner");
113 109

  
114
		folderName.setText(folder.getName());
110

  
111
        folderName.setText(folder.getName());
115 112

  
116 113
        VerticalPanel permPanel = new VerticalPanel();
117 114
        FileShareDialog.PrivateSharingImages images = GWT.create(FileShareDialog.PrivateSharingImages.class);
......
124 121
            public void onClick(ClickEvent event) {
125 122
                PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);
126 123
                dlg.center();
124
                checkUpdateButtonVisibility();
127 125
            }
128 126
        });
129 127
        addUser.addStyleName("button");
......
133 131
        Button add = new Button("Add Group", new ClickHandler() {
134 132
            @Override
135 133
            public void onClick(ClickEvent event) {
136
            	if (app.getAccount().getGroups().isEmpty()) {
134
                if(app.getAccount().getGroups().isEmpty()) {
137 135
                    new GroupCreateDialog(app, new Command() {
138
						
139
						@Override
140
						public void execute() {
141
			            	if (app.getAccount().getGroups().isEmpty())
142
			            		return;
143
			                PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
144
			                dlg.center();
145
						}
146
					}).center();
147
            	}
148
            	else {
149
	                PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
150
	                dlg.center();
151
            	}
136
                        @Override
137
                        public void execute() {
138
                            if(app.getAccount().getGroups().isEmpty()) {
139
                                return;
140
                            }
141
                            PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
142
                            dlg.center();
143
                            checkUpdateButtonVisibility();
144
                        }
145
                    }).center();
146
                }
147
                else {
148
                    PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
149
                    dlg.center();
150
                    checkUpdateButtonVisibility();
151
                }
152 152
            }
153 153
        });
154 154
        add.addStyleName("button");
......
162 162

  
163 163
        outer.add(inner);
164 164

  
165
		// Create the 'Create/Update' button, along with a listener that hides the dialog
166
		// when the button is clicked and quits the application.
167
		String okLabel = "Update";
168
		final Button ok = new Button(okLabel, new ClickHandler() {
169
			@Override
170
			public void onClick(ClickEvent event) {
171
				updateFolder();
172
				closeDialog();
173
			}
174
		});
175
		ok.addStyleName("button");
176
		outer.add(ok);
165
        // Create the 'Create/Update' button, along with a listener that hides the dialog
166
        // when the button is clicked and quits the application.
167
        final String okLabel = "Update";
168
        updateButton = new Button(okLabel, new ClickHandler() {
169
            @Override
170
            public void onClick(ClickEvent event) {
171
                updateFolder();
172
                closeDialog();
173
            }
174
        });
175
        updateButton.addStyleName("button");
176
        checkUpdateButtonVisibility();
177
        outer.add(updateButton);
177 178
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
178 179

  
179 180
        setWidget(outer);
180
	}
181

  
182
	@Override
183
	protected void onPreviewNativeEvent(NativePreviewEvent preview) {
184
		super.onPreviewNativeEvent(preview);
185

  
186
		NativeEvent evt = preview.getNativeEvent();
187
		if (evt.getType().equals(KeyDownEvent.getType().getName()))
188
			// Use the popup's key preview hooks to close the dialog when either
189
			// enter or escape is pressed.
190
			switch (evt.getKeyCode()) {
191
				case KeyCodes.KEY_ENTER:
192
					updateFolder();
181
    }
182

  
183
    private void checkUpdateButtonVisibility() {
184
        if(!this._initialPermissionCheck) {
185
            updateButton.setVisible(true);
186
            return;
187
        }
188

  
189
        updateButton.setVisible(permList.hasPermissions());
190

  
191
        this._initialPermissionCheck = false;
192
    }
193

  
194
    @Override
195
    protected void onPreviewNativeEvent(NativePreviewEvent preview) {
196
        super.onPreviewNativeEvent(preview);
197

  
198
        NativeEvent evt = preview.getNativeEvent();
199
        if(evt.getType().equals(KeyDownEvent.getType().getName()))
200
        // Use the popup's key preview hooks to close the dialog when either
201
        // enter or escape is pressed.
202
        {
203
            switch(evt.getKeyCode()) {
204
                case KeyCodes.KEY_ENTER:
205
                    updateFolder();
193 206
                    closeDialog();
194
					break;
195
				case KeyCodes.KEY_ESCAPE:
196
					closeDialog();
197
					break;
198
			}
199
	}
200

  
201

  
202
	/**
203
	 * Enables IE selection prevention and hides the dialog
204
	 * (we disable the prevention on creation of the dialog)
205
	 */
206
	public void closeDialog() {
207
		Pithos.preventIESelection();
208
		hide();
209
	}
210

  
211
	void updateFolder() {
207
                    break;
208
                case KeyCodes.KEY_ESCAPE:
209
                    closeDialog();
210
                    break;
211
            }
212
        }
213
    }
214

  
215
    /**
216
     * Enables IE selection prevention and hides the dialog
217
     * (we disable the prevention on creation of the dialog)
218
     */
219
    public void closeDialog() {
220
        Pithos.preventIESelection();
221
        hide();
222
    }
223

  
224
    void updateFolder() {
212 225
        final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);
213
        updateMetadata(folder.getUri() + "?update=", perms);
214
	}
226
        updateMetadata(
227
            folder.getUri() + Const.QUESTION_MARK_UPDATE_EQ,
228
            perms
229
        );
230
    }
215 231

  
216
	protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) {
217
        if (newPermissions != null) {
232
    protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) {
233
        if(newPermissions != null) {
218 234
            PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwnerID(), path) {
219 235
                @Override
220 236
                public void onSuccess(Resource result) {
221 237
                    app.updateFolder(folder.getParent(), false, new Command() {
222
						
223
						@Override
224
						public void execute() {
225
							app.updateMySharedRoot();
226
						}
227
					}, true);
238
                        @Override
239
                        public void execute() {
240
                            app.updateMySharedRoot();
241
                        }
242
                    }, true);
228 243
                }
229 244

  
230 245
                @Override
231 246
                public void onError(Throwable t) {
232
                    GWT.log("", t);
233
					app.setError(t);
234
                    if (t instanceof RestException) {
235
                    	if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder
247
                    app.setError(t);
248
                    if(t instanceof RestException) {
249
                        if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder
236 250
                            final String path1 = folder.getUri();
237 251
                            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path1) {
238 252
                                @Override
239 253
                                public void onSuccess(Resource result) {
240
                                	updateMetadata(path, newPermissions);
254
                                    updateMetadata(path, newPermissions);
241 255
                                }
242 256

  
243 257
                                @Override
244 258
                                public void onError(Throwable _t) {
245
                                    GWT.log("", _t);
246
            						app.setError(_t);
247
                                    if(_t instanceof RestException){
259
                                    app.setError(_t);
260
                                    if(_t instanceof RestException) {
248 261
                                        app.displayError("Unable to update folder: " + ((RestException) _t).getHttpStatusText());
249 262
                                    }
250
                                    else
263
                                    else {
251 264
                                        app.displayError("System error modifying folder: " + _t.getMessage());
265
                                    }
252 266
                                }
253 267

  
254
                				@Override
255
                				protected void onUnauthorized(Response response) {
256
                					app.sessionExpired();
257
                				}
268
                                @Override
269
                                protected void onUnauthorized(Response response) {
270
                                    app.sessionExpired();
271
                                }
258 272
                            };
259 273
                            newFolder.setHeader("X-Auth-Token", app.getUserToken());
260 274
                            newFolder.setHeader("Content-Type", "application/folder");
261 275
                            newFolder.setHeader("Accept", "*/*");
262 276
                            newFolder.setHeader("Content-Length", "0");
263 277
                            Scheduler.get().scheduleDeferred(newFolder);
264
                    	}
265
                    	else if (((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) {
266
                    		app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set");
267
                    	}
268
                    	else
269
                    		app.displayError("Εrror modifying folder: " + t.getMessage());
278
                        }
279
                        else if(((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) {
280
                            app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set");
281
                        }
282
                        else {
283
                            app.displayError("Εrror modifying folder: " + t.getMessage());
284
                        }
285
                    }
286
                    else {
287
                        app.displayError("System error modifying folder: " + t.getMessage());
270 288
                    }
271
                    else
272
                    	app.displayError("System error modifying folder: " + t.getMessage());
273 289
                }
274 290

  
275
				@Override
276
				protected void onUnauthorized(Response response) {
277
					app.sessionExpired();
278
				}
291
                @Override
292
                protected void onUnauthorized(Response response) {
293
                    app.sessionExpired();
294
                }
279 295
            };
280 296
            updateFolder.setHeader("X-Auth-Token", app.getUserToken());
281 297
            String readPermHeader = "read=";
282 298
            String writePermHeader = "write=";
283
            for (String u : newPermissions.keySet()) {
299
            for(String u : newPermissions.keySet()) {
284 300
                Boolean[] p = newPermissions.get(u);
285
                if (p[0] != null && p[0])
301
                if(p[0] != null && p[0]) {
286 302
                    readPermHeader += u + ",";
287
                if (p[1] != null && p[1])
303
                }
304
                if(p[1] != null && p[1]) {
288 305
                    writePermHeader += u + ",";
306
                }
289 307
            }
290
            if (readPermHeader.endsWith("="))
308
            if(readPermHeader.endsWith("=")) {
291 309
                readPermHeader = "";
292
            else if (readPermHeader.endsWith(","))
310
            }
311
            else if(readPermHeader.endsWith(",")) {
293 312
                readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);
294
            if (writePermHeader.endsWith("="))
313
            }
314
            if(writePermHeader.endsWith("=")) {
295 315
                writePermHeader = "";
296
            else if (writePermHeader.endsWith(","))
316
            }
317
            else if(writePermHeader.endsWith(",")) {
297 318
                writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);
298
            String permHeader = readPermHeader +  ((readPermHeader.length()  > 0 && writePermHeader.length() > 0) ?  ";" : "") + writePermHeader;
299
            if (permHeader.length() == 0)
319
            }
320
            String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader;
321
            if(permHeader.length() == 0) {
300 322
                permHeader = "~";
301
            else
302
            	permHeader = URL.encodePathSegment(permHeader);
323
            }
324
            else {
325
                permHeader = URL.encodePathSegment(permHeader);
326
            }
303 327
            updateFolder.setHeader("X-Object-Sharing", permHeader);
304 328
            Scheduler.get().scheduleDeferred(updateFolder);
305 329
        }
306
        else
330
        else {
307 331
            app.updateFolder(folder.getParent(), false, new Command() {
308
				
309
				@Override
310
				public void execute() {
311
					app.updateMySharedRoot();
312
				}
313
			}, true);
332
                @Override
333
                public void execute() {
334
                    app.updateMySharedRoot();
335
                }
336
            }, true);
337
        }
314 338
    }
315 339
}
b/src/gr/grnet/pithos/web/client/PermissionsList.java
34 34
 */
35 35
package gr.grnet.pithos.web.client;
36 36

  
37
import java.util.HashMap;
38
import java.util.Map;
39

  
40 37
import com.google.gwt.event.dom.client.ClickEvent;
41 38
import com.google.gwt.event.dom.client.ClickHandler;
42 39
import com.google.gwt.event.logical.shared.ValueChangeEvent;
43 40
import com.google.gwt.event.logical.shared.ValueChangeHandler;
44 41
import com.google.gwt.user.client.Command;
45
import com.google.gwt.user.client.ui.AbstractImagePrototype;
46
import com.google.gwt.user.client.ui.Anchor;
47
import com.google.gwt.user.client.ui.Composite;
48
import com.google.gwt.user.client.ui.FlexTable;
49
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
50
import com.google.gwt.user.client.ui.RadioButton;
51
import com.google.gwt.user.client.ui.VerticalPanel;
42
import com.google.gwt.user.client.ui.*;
52 43
import gr.grnet.pithos.web.client.catalog.UpdateUserCatalogs;
53 44
import gr.grnet.pithos.web.client.catalog.UserCatalogs;
54 45

  
46
import java.util.HashMap;
47
import java.util.Map;
48

  
55 49

  
56 50
public class PermissionsList extends Composite {
57 51

  
58
	Map<String, Boolean[]> permissions = null;
59
	
60
	final FileShareDialog.PrivateSharingImages images;
61
	
62
	final VerticalPanel permPanel = new VerticalPanel();
63
	
64
	final FlexTable permTable = new FlexTable();
65
	
66
	final String owner;
67
	
68
	protected boolean hasChanges = false;
52
    Map<String, Boolean[]> permissions = null;
53

  
54
    final FileShareDialog.PrivateSharingImages images;
55

  
56
    final VerticalPanel permPanel = new VerticalPanel();
57

  
58
    final FlexTable permTable = new FlexTable();
59

  
60
    final String owner;
61

  
62
    protected boolean hasChanges = false;
69 63

  
70 64
    private boolean readonly = false;
71
    
65

  
72 66
    Command changePermissionsCallback;
73 67

  
74 68
    private final Pithos app;
75
	
76
	public PermissionsList(Pithos app, final FileShareDialog.PrivateSharingImages theImages, Map<String, Boolean[]> thePermissions, String theOwner, boolean inheritsPermissions, Command _changePermissionsCallback){
69

  
70
    public PermissionsList(
71
        Pithos app,
72
        final FileShareDialog.PrivateSharingImages theImages,
73
        Map<String, Boolean[]> thePermissions,
74
        String theOwner,
75
        boolean inheritsPermissions,
76
        Command _changePermissionsCallback
77
    ) {
77 78
        this.app = app;
78
		changePermissionsCallback = _changePermissionsCallback;
79
		images = theImages;
80
		owner = theOwner;
81
		permissions =  new HashMap<String, Boolean[]>(thePermissions);
82
		permTable.setText(0, 0, "Users/Groups");
83
		permTable.setText(0, 1, "Read Only");
84
		permTable.setText(0, 2, "Read/Write");
85
		permTable.setText(0, 3, "");
86
		permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
87
		permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
88
		permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
89
		permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
90
		permPanel.add(permTable);
91
		permPanel.addStyleName("pithos-TabPanelBottom");
92
		initWidget(permPanel);
93
		updatePermissionTable();
94
	}
95

  
96
	public boolean hasChanges(){
97
		return hasChanges;
98
	}
99

  
100
	/**
101
	 * Retrieve the permissions.
102
	 *
103
	 * @return the permissions
104
	 */
105
	public Map<String, Boolean[]> getPermissions() {
106
		return permissions;
107
	}
108

  
109
	public void addPermission(String userID, boolean read, boolean write){
110
		permissions.put(userID, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)});
111
		hasChanges = true;
79
        changePermissionsCallback = _changePermissionsCallback;
80
        images = theImages;
81
        owner = theOwner;
82
        permissions = new HashMap<String, Boolean[]>(thePermissions);
83
        updatePermissionsHeader();
84
        permPanel.add(permTable);
85
        permPanel.addStyleName("pithos-TabPanelBottom");
86
        initWidget(permPanel);
112 87
        updatePermissionTable();
113
        if (changePermissionsCallback != null)
114
        	changePermissionsCallback.execute();
115
	}
116

  
117
	/**
118
	 * Shows the permission table 
119
	 * 
120
	 */
121
	void updatePermissionTable(){
122
		int i = 1;
88
    }
89

  
90
    private void updatePermissionsHeader() {
91
        if(hasPermissions()) {
92
            permTable.setText(0, 0, "Users/Groups");
93
            permTable.setText(0, 1, "Read Only");
94
            permTable.setText(0, 2, "Read/Write");
95
            permTable.setText(0, 3, "");
96
            permTable.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels");
97
            permTable.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels");
98
            permTable.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels");
99
            permTable.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels");
100
        }
101
        else {
102
            permTable.setText(0, 0, "");
103
            permTable.setText(0, 1, "");
104
            permTable.setText(0, 2, "");
105
            permTable.setText(0, 3, "");
106
        }
107
    }
108

  
109
    public boolean hasPermissions() {
110
        return permissionCount() > 0;
111
    }
112

  
113
    public int permissionCount() {
114
        return permissions == null
115
            ? 0
116
            : permissions.size();
117
    }
118

  
119
    public boolean hasChanges() {
120
        return hasChanges;
121
    }
122

  
123
    /**
124
     * Retrieve the permissions.
125
     *
126
     * @return the permissions
127
     */
128
    public Map<String, Boolean[]> getPermissions() {
129
        return permissions;
130
    }
131

  
132
    public void addPermission(String userID, boolean read, boolean write) {
133
        permissions.put(userID, new Boolean[]{Boolean.valueOf(read), Boolean.valueOf(write)});
134
        hasChanges = true;
135
        updatePermissionTable();
136
        if(changePermissionsCallback != null) {
137
            changePermissionsCallback.execute();
138
        }
139
    }
140

  
141
    private boolean isGroup(String userID) {
142
        return userID.contains(Const.COLON);
143
    }
144

  
145
    /**
146
     * Shows the permission table
147
     */
148
    void updatePermissionTable() {
149
        int i = 1;
123 150
        final int ii = i;
124
        for (int j=1; j<permTable.getRowCount(); j++)
151
        for(int j = 1; j < permTable.getRowCount(); j++) {
125 152
            permTable.removeRow(j);
126
		for(final String userID : permissions.keySet()) {
127
            if (!userID.contains(":")) {
128
                 //not a group
153
        }
154

  
155
        updatePermissionsHeader();
156

  
157
        for(final String userID : permissions.keySet()) {
158
            if(!isGroup(userID)) {
129 159
                final String displayName = app.getDisplayNameForUserID(userID);
130 160
                if(displayName != null) {
131 161
                    permTable.setHTML(
132 162
                        i,
133 163
                        0,
134
                        "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + "&nbsp;" + displayName + "</span>"
164
                        Const.inSpan(
165
                            AbstractImagePrototype.create(
166
                                images.permUser()).getHTML() +
167
                                Const.HTML_NBSP +
168
                                displayName
169
                        )
135 170
                    );
136 171
                }
137 172
                else {
......
142 177
                            permTable.setHTML(
143 178
                                ii,
144 179
                                0,
145
                                "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + "&nbsp;" + displayName + "</span>"
180
                                Const.inSpan(
181
                                    AbstractImagePrototype.create(
182
                                        images.permUser()).getHTML() +
183
                                        Const.HTML_NBSP +
184
                                        displayName
185
                                )
146 186
                            );
147 187
                        }
148 188
                    }.scheduleDeferred();
149 189
                }
150 190
            }
151 191
            else {
152
                permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + "&nbsp;" + userID.split(":")[1].trim() + "</span>");
192
                permTable.setHTML(
193
                    i,
194
                    0,
195
                    Const.inSpan(
196
                        AbstractImagePrototype.create(
197
                            images.permGroup()).getHTML() +
198
                            Const.HTML_NBSP +
199
                            userID.split(Const.COLON)[1].trim()
200
                    )
201
                );
153 202
            }
154 203
            permTable.getFlexCellFormatter().setStyleName(i, 0, "props-values");
155 204

  
......
157 206
            Boolean readP = userPerms[0];
158 207
            Boolean writeP = userPerms[1];
159 208

  
160
			RadioButton read = new RadioButton("permissions" + i);
161
			read.setValue(readP != null ? readP : false);
209
            RadioButton read = new RadioButton("permissions" + i);
210
            read.setValue(readP != null ? readP : false);
162 211
            permTable.setWidget(i, 1, read);
163 212
            permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
164 213

  
......
167 216
            permTable.setWidget(i, 2, write);
168 217
            permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
169 218

  
170
            if (!readonly) {
219
            if(!readonly) {
171 220
                read.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
172 221
                    @Override
173 222
                    public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) {
......
175 224
                        ps[0] = booleanValueChangeEvent.getValue();
176 225
                        ps[1] = !booleanValueChangeEvent.getValue();
177 226
                        hasChanges = true;
178
                        if (changePermissionsCallback != null)
179
                        	changePermissionsCallback.execute();
227
                        if(changePermissionsCallback != null) {
228
                            changePermissionsCallback.execute();
229
                        }
180 230
                    }
181 231
                });
182 232
                write.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
......
186 236
                        ps[0] = !booleanValueChangeEvent.getValue();
187 237
                        ps[1] = booleanValueChangeEvent.getValue();
188 238
                        hasChanges = true;
189
                        if (changePermissionsCallback != null)
190
                        	changePermissionsCallback.execute();
239
                        if(changePermissionsCallback != null) {
240
                            changePermissionsCallback.execute();
241
                        }
191 242
                    }
192 243
                });
193 244
                Anchor removeButton = new Anchor("remove");
......
198 249
                        permissions.remove(userID);
199 250
                        updatePermissionTable();
200 251
                        hasChanges = true;
201
                        if (changePermissionsCallback != null)
202
                        	changePermissionsCallback.execute();
252
                        if(changePermissionsCallback != null) {
253
                            changePermissionsCallback.execute();
254
                        }
203 255
                    }
204 256
                });
205 257
                permTable.setWidget(i, 3, removeButton);
......
209 261
                read.setEnabled(false);
210 262
                write.setEnabled(false);
211 263
            }
212
			i++;
213
		}
214
	}
264
            i++;
265
        }
266
    }
215 267
}

Also available in: Unified diff