From 6e1827810388387804b9700f7ba6f5a377c6241a Mon Sep 17 00:00:00 2001 From: Tobias Spitzer Date: Fri, 25 Jul 2014 12:15:09 +0200 Subject: Suchfenster um Reiter Vorlage ergänzt --- .../src/gui/lecture/DeleteLecture_GUI.java | 108 ++++++++++++--------- 1 file changed, 63 insertions(+), 45 deletions(-) (limited to 'Dozentenmodul/src/gui/lecture/DeleteLecture_GUI.java') diff --git a/Dozentenmodul/src/gui/lecture/DeleteLecture_GUI.java b/Dozentenmodul/src/gui/lecture/DeleteLecture_GUI.java index c638e440..9b3d0ef3 100644 --- a/Dozentenmodul/src/gui/lecture/DeleteLecture_GUI.java +++ b/Dozentenmodul/src/gui/lecture/DeleteLecture_GUI.java @@ -66,13 +66,13 @@ public class DeleteLecture_GUI extends JFrame { JTable tableAllLectures; JTable tablemyLectures; JTable tableCoopImages; - JTable tablePublicVorlagen; JTable tablePublicImages; private JTextField textFieldName; JTabbedPane tabbedPane; + boolean activeSearch=false; String[] titles = { "Veranstaltungsname", "Beschreibung", "G\u00fcltigkeitsdatum", "Aktiv", "Letzte Benutzung", - "Verantwortlicher", "Image", "Schlagwort", "ID" }; + "Verantwortlicher", "Image", "ID" }; ThriftConnection con = new ThriftConnection(); Client client = models.Client.clientcon.getClient(); final DefaultTableModel modelAll = new DefaultTableModel(titles, 0); @@ -95,6 +95,12 @@ public class DeleteLecture_GUI extends JFrame { con.closeThriftConnection(); System.exit(0); } + @Override + public void windowOpened(WindowEvent arg0) { + initTableModel(modelAll); + initTableModel(modelMyLectures); + textFieldName.requestFocusInWindow(); + } }); // Verhindert das Vergroessern Des Fensters setResizable(false); @@ -148,7 +154,7 @@ public class DeleteLecture_GUI extends JFrame { panel_1.setBackground(SystemColor.menu); panel_1.setBorder(new TitledBorder(null, "Filterfunktionen", TitledBorder.LEADING, TitledBorder.TOP, null, null)); - panel_1.setBounds(10, 49, 557, 131); + panel_1.setBounds(10, 49, 557, 64); contentPanel.add(panel_1); panel_1.setLayout(null); @@ -163,15 +169,22 @@ public class DeleteLecture_GUI extends JFrame { public void keyReleased(KeyEvent e) { // Textfield eingabe auslesen String stext = textFieldName.getText(); - // Wenn Textfield nicht leer if (stext != "") { + activeSearch=true; // Filtere nach der Eingabe rowSorterAll.setRowFilter(RowFilter.regexFilter( textFieldName.getText(), 0)); rowSorterMyLectures.setRowFilter(RowFilter.regexFilter( textFieldName.getText(), 0)); + }else{ + activeSearch=false; + String username = person.verantwortlicher.getName() + " " + + person.verantwortlicher.getVorname(); + rowSorterMyLectures.setRowFilter(RowFilter.regexFilter( + username, 5)); + rowSorterAll.setRowFilter(null); } } }); @@ -180,22 +193,6 @@ public class DeleteLecture_GUI extends JFrame { panel_1.add(textFieldName); textFieldName.setColumns(10); - JLabel lblErweiterteSuche = new JLabel( - "Erweiterte Suche*Folgt noch*"); - lblErweiterteSuche.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent arg0) { - // oeffnet das Fenster Extended GUI - - //ExtendedSearchForImages_GUI es = new ExtendedSearchForImages_GUI(); - //es.setVisible(true); - } - }); - lblErweiterteSuche.setForeground(Color.BLUE); - - lblErweiterteSuche.setBounds(336, 106, 184, 14); - panel_1.add(lblErweiterteSuche); - JLabel lblHauptmen = new JLabel("Hauptmen\u00FC"); lblHauptmen.addMouseListener(new MouseAdapter() { @Override @@ -238,15 +235,15 @@ public class DeleteLecture_GUI extends JFrame { rowSorterMyLectures.setRowFilter(RowFilter.regexFilter( username, 5)); } else if (tabbedPane.getSelectedIndex() == 1) { - + rowSorterAll.setRowFilter(null); } } }); - tabbedPane.setBounds(10, 197, 557, 300); + tabbedPane.setBounds(10, 124, 557, 373); contentPanel.add(tabbedPane); - initTableModel(modelMyLectures); + JScrollPane scrollPaneAllImages = new JScrollPane(); tableAllLectures = new JTable(); @@ -256,8 +253,7 @@ public class DeleteLecture_GUI extends JFrame { tableAllLectures.getColumnModel().getColumn(3).sizeWidthToFit(); tableAllLectures.getColumnModel().getColumn(4).sizeWidthToFit(); tableAllLectures.getColumnModel().getColumn(5).sizeWidthToFit(); - initTableModel(modelAll); - + tableAllLectures.setRowSorter(rowSorterAll); JScrollPane scrollPaneMyImage = new JScrollPane(); tablemyLectures = new JTable(); tablemyLectures.setModel(modelMyLectures); @@ -272,7 +268,7 @@ public class DeleteLecture_GUI extends JFrame { scrollPaneMyImage.setViewportView(tablemyLectures); tabbedPane.addTab("Meine Veranstaltungen", null, scrollPaneMyImage, null); - tableAllLectures.setRowSorter(rowSorterAll); + scrollPaneAllImages.setViewportView(tableAllLectures); tabbedPane.addTab("Alle", null, scrollPaneAllImages, null); @@ -301,30 +297,17 @@ public class DeleteLecture_GUI extends JFrame { tablePublicImages.getColumnModel().getColumn(5).sizeWidthToFit(); scrollPanePublicImages.setViewportView(tablePublicImages); - tabbedPane.addTab("\u00D6ffentliche Images", null, + tabbedPane.addTab("\u00D6ffentliche Veranstaltungen", null, scrollPanePublicImages, null); tabbedPane.setEnabledAt(3, false); - JScrollPane scrollPanePublicVorlagen = new JScrollPane(); - tablePublicVorlagen = new JTable(); - tablePublicVorlagen.setModel(model); - tablePublicVorlagen.getColumnModel().getColumn(1).sizeWidthToFit(); - tablePublicVorlagen.getColumnModel().getColumn(2).sizeWidthToFit(); - tablePublicVorlagen.getColumnModel().getColumn(3).sizeWidthToFit(); - tablePublicVorlagen.getColumnModel().getColumn(4).sizeWidthToFit(); - tablePublicVorlagen.getColumnModel().getColumn(5).sizeWidthToFit(); - - scrollPanePublicVorlagen.setViewportView(tablePublicVorlagen); - tabbedPane.addTab("\u00D6ffentliche Vorlagen", null, - scrollPanePublicVorlagen, null); - tabbedPane.setEnabledAt(4, false); - button = new JButton("L\u00F6schen"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String lectureID=""; int eingabe; - + String username = person.verantwortlicher.getName() + " " + + person.verantwortlicher.getVorname(); //check if a row is selected if (tablemyLectures.getSelectedRowCount() !=0){ //a row is selected @@ -335,7 +318,42 @@ public class DeleteLecture_GUI extends JFrame { if (eingabe == JOptionPane.YES_OPTION) { //user has confirmed deletion, now get the ID of the selected lecture - lectureID = modelMyLectures.getValueAt(tablemyLectures.convertColumnIndexToModel(tablemyLectures.getSelectedRow()), 8).toString(); + lectureID = modelMyLectures.getValueAt(tablemyLectures.convertColumnIndexToModel(tablemyLectures.getSelectedRow()), 7).toString(); + System.out.println("L\u00f6sche Lecture "+lectureID); + try { + if(client.deleteLecture(lectureID, person.verantwortlicher.getHochschule(),person.verantwortlicher.getUsername())){ + System.out.println("L\u00f6schen erfolgreich"); + //delete successful + + DeleteLecture_GUI dl = new DeleteLecture_GUI(); + dl.setVisible(true); + dispose(); + } else { + //delete not successful + JOptionPane + .showMessageDialog( + null, + "L\u00f6schen aus Datenbank fehlgeschlagen.", + "Fehler", + JOptionPane.INFORMATION_MESSAGE); + } + } catch (TException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }//end delete + }//end ask for confirmation + + }//end check if a row is selected + else if (tableAllLectures.getSelectedRowCount() !=0 && tableAllLectures.getValueAt(tableAllLectures.getSelectedRow(), 5).toString().equals(username)){ + //a row is selected + //ask for confirmation + eingabe = JOptionPane.showConfirmDialog(null, + "Wollen Sie diese Daten l\u00f6schen?", "L\u00f6schen?", + JOptionPane.YES_NO_OPTION); + + if (eingabe == JOptionPane.YES_OPTION) { + //user has confirmed deletion, now get the ID of the selected lecture + lectureID = tableAllLectures.getValueAt(tableAllLectures.convertColumnIndexToModel(tableAllLectures.getSelectedRow()), 7).toString(); System.out.println("L\u00f6sche Lecture "+lectureID); try { if(client.deleteLecture(lectureID, person.verantwortlicher.getHochschule(),person.verantwortlicher.getUsername())){ @@ -476,8 +494,8 @@ public class DeleteLecture_GUI extends JFrame { lectures.get(x).starttime + " " + lectures.get(x).endtime, lectures.get(x).isActive, lectures.get(x).lastused, - lectures.get(x).username, " ", - lectures.get(x).imagename, lectures.get(x).id }; + lectures.get(x).username, + lectures.get(x).imagename,lectures.get(x).id }; // Fuege diese Objekte der Tabelle hinzu model.addRow(obj); x++; -- cgit v1.2.3-55-g7522