private void updateDisplays() { if (sliceList.isSelectionEmpty()) return; Slice d = (Slice) sliceList.getSelectedValue(); if (d.urn.equals(textFieldSliceURN.getText())) // is an updated really necessary? return; textFieldSliceURN.setText(d.urn); textAreaDesc.setText(d.desc); textFieldExpiry.setText(Utils.utcTolocal(d.expiry)); textFieldCreation.setText(Utils.utcTolocal(d.creation)); textFieldProjectURN.setText(d.urnProject); tableModel.clear(); // if(d.members.size() == 0) LinkedList<Membership> members = SliceAuthorityAPI.lookupMembers(d.urn, "SLICE"); if (members == null) { showErrorMessage(); return; } d.members = members; for (int i = 0; i < members.size(); i++) { tableModel.add(members.get(i).urn, members.get(i).role); } }
private void showChangeRoleDialog() { Slice slice = (Slice) sliceList.getSelectedValue(); int row = memberTable.convertRowIndexToModel(memberTable.getSelectedRow()); String role = slice.members.get(row).role; String availableRoles[]; if (role.equals("MEMBER")) availableRoles = new String[] {"LEAD", "ADMIN"}; else if (role.equals("ADMIN")) availableRoles = new String[] {"LEAD", "MEMBER"}; else { JOptionPane.showMessageDialog( this, "There must always be a LEAD role for a slice.\nAssigning LEAD role to another member would automatically change this user's role to MEMBER.", "Alter Role", JOptionPane.INFORMATION_MESSAGE); return; } String newRole = (String) JOptionPane.showInputDialog( null, "Select new role member:", "Change Member Role", JOptionPane.PLAIN_MESSAGE, null, availableRoles, availableRoles[0]); if (newRole != null) { Membership rsp = SliceAuthorityAPI.changeMemberRole( slice.urn, slice.members.get(row).urn, newRole, slice.members.get(row).type); if (rsp != null) { // Let's perform a lookup again to get a fresh member list LinkedList<Membership> members = SliceAuthorityAPI.lookupMembers(slice.urn, slice.members.get(row).type); if (members == null) return; slice.members = members; tableModel.clear(); for (int i = 0; i < slice.members.size(); i++) tableModel.add(slice.members.get(i).urn, slice.members.get(i).role); } else showErrorMessage(); } }
private Slice showNewSliceDialog() { Object[] allProjects = mainGUI.getProjectsArray(); if (allProjects.length == 0) { JOptionPane.showMessageDialog( this, "Please first create a project.", "Create Slice", JOptionPane.INFORMATION_MESSAGE); return null; } String[] projectNames = new String[allProjects.length]; for (int i = 0; i < projectNames.length; i++) projectNames[i] = ((Project) allProjects[i]).name; JPanel infoPanel = new JPanel(); infoPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(10, 0, 0, 0); // top padding c.weightx = 0.1; c.gridx = 0; c.gridy = 0; infoPanel.add(new JLabel("Name:"), c); c.gridy = 1; infoPanel.add(new JLabel("Project:"), c); c.gridy = 2; infoPanel.add(new JLabel("Description:"), c); JComboBox projectBox = new JComboBox(projectNames); JTextField name = new JTextField(""); AbstractDocument doc = (AbstractDocument) name.getDocument(); doc.setDocumentFilter(new PatternFilter("^[a-zA-Z0-9][-a-zA-Z0-9]{0,18}")); name.setColumns(30); JTextArea desc = new JTextArea(""); c.weightx = 0.9; c.gridx = 1; c.gridy = 0; infoPanel.add(name, c); c.gridy = 1; infoPanel.add(projectBox, c); c.gridy = 2; c.ipady = 100; infoPanel.add(new JScrollPane(desc), c); int response; do { response = JOptionPane.showConfirmDialog( this, infoPanel, "New Slice", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); name.setBackground(name.getText().trim().length() == 0 ? Color.pink : Color.white); desc.setBackground(desc.getText().trim().length() == 0 ? Color.pink : Color.white); } while ((name.getText().length() == 0 || desc.getText().length() == 0) && response == JOptionPane.OK_OPTION); if (response != JOptionPane.OK_OPTION) return null; else { Slice d = new Slice(); d.name = name.getText().trim(); d.desc = desc.getText().trim(); d.urnProject = ((Project) allProjects[projectBox.getSelectedIndex()]).urn; return d; } }