diff options
Diffstat (limited to 'dozentenmodul/src/main/java/gui/lecture/PermissionEditLecture_GUI.java')
| -rw-r--r-- | dozentenmodul/src/main/java/gui/lecture/PermissionEditLecture_GUI.java | 470 |
1 files changed, 0 insertions, 470 deletions
diff --git a/dozentenmodul/src/main/java/gui/lecture/PermissionEditLecture_GUI.java b/dozentenmodul/src/main/java/gui/lecture/PermissionEditLecture_GUI.java deleted file mode 100644 index 037de54c..00000000 --- a/dozentenmodul/src/main/java/gui/lecture/PermissionEditLecture_GUI.java +++ /dev/null @@ -1,470 +0,0 @@ -package gui.lecture; - -import gui.helper.ColumnSelector; -import gui.intro.MainMenue_GUI; - -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.SystemColor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.swing.JButton; -import javax.swing.JInternalFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JTable; -import javax.swing.JTextPane; -import javax.swing.ScrollPaneConstants; -import javax.swing.border.EmptyBorder; -import javax.swing.border.TitledBorder; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableColumn; - -import models.Lecture; -import models.RightsManagement; -import models.SessionData; -import models.person; - -import org.apache.thrift.TException; -import org.openslx.sat.thrift.iface.Person; -import org.openslx.thrifthelper.ThriftManager; - -import util.CheckIntegrity; -import util.GuiManager; -import util.ListAllOtherUsers_GUI; - -@SuppressWarnings("serial") -public class PermissionEditLecture_GUI extends JInternalFrame { - - private final JPanel contentPanel = new JPanel(); - private JTable table; - private String[] titles = { "Name", "Lesen", "Schreiben", "Admin", "userID" }; - private List<Person> map = null; // List of people who have rights - public static final String HELP_MESSAGE = "<html><div align=\"center\">" - + "Hier können Sie die Berechtigungen für Ihre Veranstaltung festlegen.<br />" - + "Es wird unterschieden, ob innerhalb der Suite (dieses Programm) Änderungen vorgenommen werden dürfen, <br />" - + "und/oder ob die Veranstaltung auch im VMChooser angezeigt wird." + "</div></html>"; - - final DefaultTableModel model = new DefaultTableModel(titles, 0) { - - public boolean isCellEditable(int rowIndex, int mColIndex) { - if (mColIndex >= 1) { - return true; - } - return false; - } - - public Class<?> getColumnClass(int c) { - switch (c) { - case 0: - return String.class; - default: - return Boolean.class; - } - } - - }; - - public PermissionEditLecture_GUI() { - setResizable(false); - setTitle("bwLehrpool Suite - Berechtigungen - " + person.verantwortlicher.getUserID()); - - setBounds(0, 0, 603, 722); - - getContentPane().setLayout(null); - { - JPanel panel = new JPanel(); - panel.setBackground(SystemColor.menu); - panel.setBounds(10, 11, 577, 57); - getContentPane().add(panel); - panel.setLayout(null); - { - JLabel lblNewLabel = new JLabel("Veranstaltung - Berechtigungen"); - lblNewLabel.setBounds(10, 11, 509, 22); - panel.add(lblNewLabel); - lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 18)); - } - - JTextPane txtpnBitteWhlenSie = new JTextPane(); - txtpnBitteWhlenSie.setEditable(false); - txtpnBitteWhlenSie.setBackground(SystemColor.menu); - txtpnBitteWhlenSie - .setText("Definieren Sie hier bitte die gewünschten Berechtigungen für Ihre Veranstaltung"); - txtpnBitteWhlenSie.setBounds(10, 36, 509, 32); - panel.add(txtpnBitteWhlenSie); - } - contentPanel.setBounds(10, 85, 577, 531); - contentPanel.setBackground(SystemColor.menu); - contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(contentPanel); - contentPanel.setLayout(null); - - JPanel panel = new JPanel(); - panel.setLayout(null); - panel.setBorder(new TitledBorder(null, "Beschreibung", TitledBorder.LEADING, TitledBorder.TOP, null, - null)); - panel.setBackground(SystemColor.menu); - panel.setBounds(10, 35, 557, 130); - contentPanel.add(panel); - - JLabel lblLesen = new JLabel("Lesen"); - lblLesen.setBounds(28, 18, 90, 20); - panel.add(lblLesen); - - JLabel lblVeranstaltungIstIn = new JLabel( - "Veranstaltung ist in bwLehrpool Suite und VMchooser für sichtbar."); - lblVeranstaltungIstIn.setBounds(128, 18, 419, 20); - panel.add(lblVeranstaltungIstIn); - - JLabel lblSchreiben = new JLabel("Schreiben"); - lblSchreiben.setBounds(28, 38, 90, 20); - panel.add(lblSchreiben); - - JLabel label_5 = new JLabel( - "Veranstaltung darf angepasst und überschrieben, jedoch nicht gelöscht werden."); - label_5.setBounds(128, 38, 419, 20); - panel.add(label_5); - - JLabel label_6 = new JLabel("Admin"); - label_6.setBounds(28, 58, 90, 20); - panel.add(label_6); - - JLabel lblvolleRechteLesen = new JLabel( - "<HTML>Volle Rechte: Lesen, Schreiben, Löschen und Berechtigungen für andere Benutzer festlegen.</HTML>"); - lblvolleRechteLesen.setBounds(128, 58, 419, 35); - panel.add(lblvolleRechteLesen); - - JPanel panel_1 = new JPanel(); - panel_1.setBackground(SystemColor.menu); - panel_1.setBorder(new TitledBorder(null, "Suite-Berechtigungen", TitledBorder.LEADING, - TitledBorder.TOP, null, null)); - panel_1.setBounds(10, 194, 311, 326); - contentPanel.add(panel_1); - panel_1.setLayout(null); - - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane.setBounds(10, 28, 291, 251); - panel_1.add(scrollPane); - - table = new JTable(); - table.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - checkIntegrity(-1); - } - - @Override - public void mouseReleased(MouseEvent e) { - - table.clearSelection(); //just one row is selectable - table.setRowSelectionInterval(table.rowAtPoint(e.getPoint()), table.rowAtPoint(e.getPoint())); - } - }); - - table.setModel(model); - table.setSelectionForeground(Color.WHITE); - table.getTableHeader().setReorderingAllowed(false); - // invisible attribute userID for identifying selected user - table.getColumnModel().getColumn(4).setWidth(0); - table.getColumnModel().getColumn(4).setMinWidth(0); - table.getColumnModel().getColumn(4).setMaxWidth(0); - - // if new session, get values for table from database - if (RightsManagement.rightsManagement.getPermittedUserList().size() <= 0) { - //System.out.println("Loading data from db"); - try { - - map = ThriftManager.getSatClient().getPermissionForUserAndLecture(SessionData.authToken, - Lecture.lecture.getid(), person.verantwortlicher.getUserID()); - Iterator<Person> i = map.iterator(); - - int x = 0; - - while (i.hasNext()) { - // erzeuge Objekte fuer die Tabelle - Object[] obj = { map.get(x).getNachname() + ", " + map.get(x).getVorname(), // Name - (boolean) map.get(x).isLecture_read(), // Read - (boolean) map.get(x).isLecture_write(), // Write - (boolean) map.get(x).isLecture_admin(), // Admin - map.get(x).getUserID() // userID - }; - // Fuege diese Objekte der Tabelle hinzu - model.addRow(obj); - - i.next(); - x++; - - } - - } catch (TException e1) { - - e1.printStackTrace(); - } - } else // read from model - { - - List<person> listt = RightsManagement.rightsManagement.getPermittedUserList(); - Iterator<person> i = listt.iterator(); - - while (i.hasNext()) { - // erzeuge Objekte fuer die Tabelle - person temp = i.next(); - - Object[] obj = { temp.getName() + ", " + temp.getVorname(), // Name - temp.isLecture_read(), // Read - temp.isLecture_write(), // Write - temp.isLecture_admin(), // Admin - temp.getUserID() // userID - }; - // Fuege diese Objekte der Tabelle hinzu - model.addRow(obj); - } - }// end set list of permitted users - - TableColumn tc1 = table.getColumnModel().getColumn(1); - tc1.setCellEditor(table.getDefaultEditor(Boolean.class)); - tc1.setCellRenderer(table.getDefaultRenderer(Boolean.class)); - tc1.setHeaderRenderer(new CheckBoxHeader(new ColumnSelector(table, 1), titles[1])); - - TableColumn tc2 = table.getColumnModel().getColumn(2); - tc2.setCellEditor(table.getDefaultEditor(Boolean.class)); - tc2.setCellRenderer(table.getDefaultRenderer(Boolean.class)); - tc2.setHeaderRenderer(new CheckBoxHeader(new ColumnSelector(table, 1, 2), titles[2])); - - TableColumn tc3 = table.getColumnModel().getColumn(3); - tc3.setCellEditor(table.getDefaultEditor(Boolean.class)); - tc3.setCellRenderer(table.getDefaultRenderer(Boolean.class)); - tc3.setHeaderRenderer(new CheckBoxHeader(new ColumnSelector(table, 1, 2, 3), titles[3])); - - scrollPane.setViewportView(table); - - JButton btnAddUser = new JButton("Hinzufügen"); - btnAddUser.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - // show list of all other relevant users - GuiManager.openPopup(new ListAllOtherUsers_GUI(table, 4)); - // give access to the table model and inform that - // the userID is position 5 in the model - } - }); - btnAddUser.setBounds(10, 290, 113, 23); - panel_1.add(btnAddUser); - - JButton btnDeleteUser = new JButton("Löschen"); - btnDeleteUser.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - - // delete selected users from table - int[] deletableRows = table.getSelectedRows(); - int pointerCorrection = 0; // after deleting a row, the length - // of selected rows is reduced by 1. - // This pointer counts the already - // deleted rows and correct the - // offset of i - - for (int i = 0; i < deletableRows.length; i++) { - model.removeRow(deletableRows[i - pointerCorrection]); - pointerCorrection++; - } - } - }); - btnDeleteUser.setBounds(133, 290, 113, 23); - panel_1.add(btnDeleteUser); - - JLabel lblHauptmen = new JLabel("Hauptmenü"); - lblHauptmen.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent arg0) { - GuiManager.show(new MainMenue_GUI()); - } - }); - lblHauptmen.setForeground(Color.BLUE); - lblHauptmen.setBounds(10, 11, 61, 14); - contentPanel.add(lblHauptmen); - - JLabel label_1 = new JLabel(">"); - label_1.setBounds(69, 11, 13, 14); - contentPanel.add(label_1); - - JLabel lblVlimage = new JLabel("Veranstaltung"); - lblVlimage.setForeground(Color.BLUE); - lblVlimage.setBounds(81, 11, 90, 14); - contentPanel.add(lblVlimage); - - JLabel label_2 = new JLabel(">"); - label_2.setBounds(181, 11, 13, 14); - contentPanel.add(label_2); - - JLabel lblNewLabel_1 = new JLabel("Bearbeiten"); - lblNewLabel_1.setBounds(194, 11, 155, 14); - contentPanel.add(lblNewLabel_1); - - JPanel panel_2 = new JPanel(); - panel_2.setLayout(null); - panel_2.setBorder(new TitledBorder(null, "Sichtbarkeit im VMChooser", TitledBorder.LEADING, - TitledBorder.TOP, null, null)); - panel_2.setBackground(SystemColor.menu); - panel_2.setBounds(331, 194, 236, 326); - contentPanel.add(panel_2); - - final JScrollPane scrollPane_1 = new JScrollPane(); - scrollPane_1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - scrollPane_1.setEnabled(false); - scrollPane_1.setBounds(16, 88, 210, 191); - panel_2.add(scrollPane_1); - - JRadioButton rdbtnAlle = new JRadioButton("Sichtbar für alle"); - rdbtnAlle.setSelected(true); - rdbtnAlle.setEnabled(false); - rdbtnAlle.setBounds(6, 32, 109, 23); - panel_2.add(rdbtnAlle); - - JRadioButton rdbtnIndividuell = new JRadioButton("Individuell"); - rdbtnIndividuell.setEnabled(false); - rdbtnIndividuell.setBounds(6, 58, 109, 23); - panel_2.add(rdbtnIndividuell); - - final JButton btnAddVmUser = new JButton("Hinzufügen"); - btnAddVmUser.setEnabled(false); - btnAddVmUser.setBounds(23, 290, 89, 23); - panel_2.add(btnAddVmUser); - - final JButton btnDelVmUser = new JButton("Löschen"); - btnDelVmUser.setEnabled(false); - btnDelVmUser.setBounds(122, 290, 89, 23); - panel_2.add(btnDelVmUser); - { - JPanel buttonPane = new JPanel(); - buttonPane.setBounds(0, 640, 597, 33); - buttonPane.setBackground(SystemColor.menu); - buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - getContentPane().add(buttonPane); - { - JButton cancelButton = new JButton("Zurück"); - cancelButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GuiManager.show(new EditLectureAllgemein_GUI()); - } - }); - cancelButton.setActionCommand("OK"); - buttonPane.add(cancelButton); - } - { - JButton continueButton = new JButton("Weiter"); - continueButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - - // before save, check integrity to avoid dblClick errors - // of rights - for (int i = 0; i < table.getRowCount(); i++) { - checkIntegrity(i); // check integrity of each line again - } - - saveTableToList(); - GuiManager.show(new EditLectureLink_GUI()); - } - }); - continueButton.setActionCommand("Cancel"); - buttonPane.add(continueButton); - getRootPane().setDefaultButton(continueButton); - } - } - - rdbtnAlle.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - scrollPane_1.setEnabled(false); - btnAddVmUser.setEnabled(false); - btnDelVmUser.setEnabled(false); - } - }); - - rdbtnIndividuell.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - scrollPane_1.setEnabled(true); - btnAddVmUser.setEnabled(true); - btnDelVmUser.setEnabled(true); - } - }); - - JSeparator separator = new JSeparator(); - separator.setBounds(0, 78, 597, 2); - getContentPane().add(separator); - - JSeparator separator_1 = new JSeparator(); - separator_1.setBounds(0, 627, 597, 2); - getContentPane().add(separator_1); - - }// end constructor - - private void checkIntegrity(int row) { - - int selectedRow; - - if (row == -1) { - selectedRow = table.getSelectedRow(); - } else { - selectedRow = row; - } - - boolean isRead, isWrite, isAdmin; - - // collect all row data - isRead = (boolean) table.getValueAt(selectedRow, 1); - isWrite = (boolean) table.getValueAt(selectedRow, 2); - isAdmin = (boolean) table.getValueAt(selectedRow, 3); - - boolean[] checkedVals = CheckIntegrity.isIntegreForLecture(isRead, isWrite, isAdmin); - - table.setValueAt(checkedVals[0], selectedRow, 1); - table.setValueAt(checkedVals[1], selectedRow, 2); - table.setValueAt(checkedVals[2], selectedRow, 3); - }// end checkIntegrity() - - // save the entered rights into the model and prepare them to be written to - // the database - private void saveTableToList() { - List<person> list = new ArrayList<person>(); - - int seperatorIndex = 0; - - // get values from table and save the checkbox values - - for (int i = 0; i < table.getRowCount(); i++) { - person temp = new person(); - - seperatorIndex = table.getModel().getValueAt(i, 0).toString().indexOf(","); - - temp.setUserID(table.getModel().getValueAt(i, 4).toString()); // get - // userID - temp.setLecture_admin(Boolean.parseBoolean(table.getModel().getValueAt(i, 3).toString())); // get Admin - temp.setLecture_write(Boolean.parseBoolean(table.getModel().getValueAt(i, 2).toString()));// get Write - temp.setLecture_read(Boolean.parseBoolean(table.getModel().getValueAt(i, 1).toString()));// get Read - seperatorIndex = table.getModel().getValueAt(i, 0).toString().indexOf(","); - temp.setName(table.getModel().getValueAt(i, 0).toString().substring(0, seperatorIndex)); - temp.setVorname(table.getModel().getValueAt(i, 0).toString().substring(seperatorIndex + 2)); - - // check if at least one checkbox is checked. If yes, save this - // entry into list, if not ignore this entry - if (temp.isLecture_admin() || temp.isLecture_write() || temp.isLecture_read()) { - // save entry - list.add(temp); - } else { - // do nothing - } - } - - RightsManagement.rightsManagement.setPermittedUserList(list); - }// end saveTableToList() - -} |
