summaryrefslogblamecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
blob: 410eb5c5d244fd86a818f9e86ecc320052ac2f5d (plain) (tree)
1
2
3
4
5
6
7
8
9

                                      
                      

                                     

                                   
                      
                                              
 
                          
                             
                                  

                                          
 
                               
                                                      
                                  
                                         
                                                                  
                                                 
                                            

                                        
 
                           

                                                            

                                                                                     
                                               
 

                                  
 

                                                                                          
                        











                                                                    


                                                                                                                                                 
                                                                       


                                                                                                        


                         
                
                                                                
                                 

                                                                



                                                                                                                                      
                                 

                         


                                                                    
                                                                                                       
                                                  








                                                                       
 






                                                                     
 







                                                                          
         
 
                                                              
                                                    
                                 




                                                                                                      
                                                                                    

                                         

                         

         
                 
                                      



                            
                                   
                                   
         
 
package org.openslx.dozmod.gui.window;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.regex.PatternSyntaxException;

import javax.swing.JFrame;
import javax.swing.RowFilter;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.window.layout.ImageListWindowLayout;
import org.openslx.dozmod.gui.wizard.ImageWizard;
import org.openslx.dozmod.thrift.ImageCache;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;

@SuppressWarnings("serial")
public class ImageListWindow extends ImageListWindowLayout {

	private final static Logger LOGGER = Logger.getLogger(ImageListWindow.class);

	public final ImageListWindow me = this;

	public ImageListWindow() {
		super();

		// filter the objects in the table depending on the search field
		searchTextField.getDocument().addDocumentListener(new DocumentListener() {
			
			@Override
			public void removeUpdate(DocumentEvent e) {
				changedUpdate(e);
			}

			@Override
			public void insertUpdate(DocumentEvent e) {
				changedUpdate(e);
			}

			@Override
			public void changedUpdate(DocumentEvent e) {
				// stuff
				try {
					imageTable.getRowSorter().setRowFilter(RowFilter.regexFilter("(?i)"+searchTextField.getText(), 0, 1, 2));
				} catch (IllegalArgumentException ex) {
					// TODO set background color of search field to something redish
					searchTextField.setBackground(Color.RED);
				}
			}
		});

		
		imageTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {
					ImageSummaryRead image = imageTable.getSelectedItem();
					if (image == null)
						return;
					ImageDetailsWindow.open((JFrame)SwingUtilities.getWindowAncestor(me), image.getImageBaseId());
				}
			}
		});
		newButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new ImageWizard(SwingUtilities.getWindowAncestor(me)).setVisible(true);
				refreshList(true);
			}
		});

		downloadButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO open download popup
			}
		});

		// delete lecture
		deleteButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO delete the image
			}
		});

		// return to mainMenu
		backButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				MainWindow.showPage(MainMenuWindow.class);
			}
		});
		
	}

	private void refreshList(final boolean forceRefresh) {
		QuickTimer.scheduleOnce(new Task() {
			@Override
			public void fire() {
				final List<ImageSummaryRead> imageList = ImageCache.get(forceRefresh);
				Gui.asyncExec(new Runnable() {
					@Override
					public void run() {
						imageTable.setData(imageList, true);
					}
				});
			}
		});
	}

	@Override
	public boolean requestHide() {
		return true;
	}

	@Override
	public void requestShow() {
		refreshList(false);
	}
}