Revision 87487bbf src/gr/grnet/pithos/web/client/PermissionsList.java

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