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

                                      

                                     

                                   
                      
 


                                          

                                               
 
                               
                                                      
                                                      
                                  
                                         
                                                                  
                                            



                                            


                                                            

                                                                                     
                                               
 

                                  
 


















                                                                                                        
                                                                                                     
                                 
                                                                        
                                                                                      

                                                  































                                                                                                                   

                         
                                                                
                                 

                                                                 
                                                                  
                                 

                         












                                                                       
 






                                                                     
 







                                                                          
         
 
                                                              
                                                    
                                 







                                                                                                      

                         

         
                 
                                      



                            
                                   
                                   
         
 
package org.openslx.dozmod.gui.window;

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 javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
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.thrift.ImageCache;
import org.openslx.dozmod.thrift.UserCache;
import org.openslx.dozmod.util.FormatHelper;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;

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) {
				// TODO: Set filter
			}
		});

		// Selection listener for the table to update the details panel when an image is clicked
		imageTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
			@Override
			public void valueChanged(ListSelectionEvent e) {
				ImageSummaryRead image = imageTable.getSelectedItem();
				if (image == null)
					return;
				// Fill detail information fields
				// Image name
				setFieldText(imageSelectedNameLabel, image.getImageName());
				// id of the lecture
				setFieldText(idInfo, image.getImageBaseId());
				// version of the image TODO last? current?
				setFieldText(versionInfo, image.getCurrentVersionId());
				// last update of image
				setFieldText(lastUpdateInfo, FormatHelper.longDate(image.getUpdateTime()));
				// permissions of this image
				ImagePermissions perms = image.getUserPermissions();
				if (perms == null)
					perms = image.getDefaultPermissions();
				if (perms != null)
					setFieldText(permissionInfo, perms.toString());
				// the owner of the selected lecture
				setFieldText(ownerInfo, FormatHelper.userName(UserCache.find(image.getOwnerId())));
				// is it a template?
				if (image.isTemplate)
					templateInfo.setText("Ja");
				else
					templateInfo.setText("Nein");

				me.invalidate();
				me.validate();
			}
			private void setFieldText(JTextField control, String content) {
				if (content == null) {
					control.setText("<null>");
				} else {
					control.setText(content);
				}
			}
		});
		imageTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent me) {
				if (me.getClickCount() == 2) {
					// TODO open details popup
				}
			}
		});
		newButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO open wizard for image creation
			}
		});

		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);
					}
				});
			}
		});
	}

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

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