Commit 232d2a93 authored by Marian Dovgialo's avatar Marian Dovgialo

#46044 hacked weblaf 1.2.8 to allow single click info updating in select signal dialog

parent 2b7d1c30
......@@ -569,6 +569,7 @@
<dependency>
<groupId>com.weblookandfeel</groupId>
<artifactId>weblaf-ui</artifactId>
<!-- SignalMLFileChooser has dirty hacks aimed at this weblaf version, be careful when changing it -->
<version>1.2.8</version>
</dependency>
......
package org.signalml.app.view.common.components.filechooser;
import com.alee.extended.filechooser.WebFileTable;
import static org.signalml.app.util.i18n.SvarogI18n._;
import java.io.File;
import java.lang.reflect.*;
import com.alee.extended.list.FileListViewType;
import com.alee.extended.list.WebFileList;
import com.alee.laf.filechooser.FileChooserViewType;
import com.alee.laf.filechooser.WebFileChooser;
import com.alee.laf.filechooser.WebFileChooserPanel;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileSystemView;
import org.signalml.app.model.components.validation.ValidationErrors;
import org.signalml.app.view.common.dialogs.errors.Dialogs;
class SingleClickWebFileChooserPanel extends WebFileChooserPanel
{
}
/**
* A file chooser which should be used by all Svarog components. Adds a
......@@ -28,9 +42,148 @@
*/
public SignalMLFileChooser() {
getFileChooserPanel().setViewType(FileChooserViewType.table);
EmbeddedFileChooserFavorites f = new EmbeddedFileChooserFavorites(this);
EmbeddedFileChooserFavorites f = new EmbeddedFileChooserFavorites(this);
this.setAccessory(f);
// will work only with weblaf 1.2.8 - dirty hacks to patch its behaviour to allow signal file info to be updated after single click it instead of double
validateWeblafWersion();
hackSetupSingleClickFileBrowsingTable();
hackSetupSingleClickFileBrowsingList();
}
void validateWeblafWersion()
{
try {
Field field = WebFileChooserPanel.class.getDeclaredField("quotedFileNameProvider");
} catch (NoSuchFieldException ex) {
Dialogs.showError("Open Signal menu weblaf single click hack incompatability! Using Weblaf version different to 1.2.8? Consider removing this hack!");
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
}
}
void hackSetupSingleClickFileBrowsingList()
{
try
{
Field field = WebFileChooserPanel.class.getDeclaredField("fileList");
field.setAccessible(true);//Very important, this allows the setting to work.
WebFileList fileList = (WebFileList) field.get(getFileChooserPanel());
fileList.addMouseListener(
new MouseAdapter ()
{
@Override
public void mouseClicked ( final MouseEvent e )
{
Method fireApproveAction;
try {
fireApproveAction = WebFileChooserPanel.class.getDeclaredMethod("fireApproveAction", ActionEvent.class);
if ( SwingUtilities.isLeftMouseButton ( e ) && fileList.getSelectedIndex () != -1 )
{
final File file = fileList.getSelectedFile ();
if ( !file.isDirectory () )
{
try {
fireApproveAction.setAccessible(true);
fireApproveAction.invoke(getFileChooserPanel(), new ActionEvent ( fileList, e.getID (), "Files selected", e.getWhen (), e.getModifiers () ));
} catch (IllegalAccessException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
} catch (NoSuchMethodException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
);
}
catch (NoSuchFieldException e)
{}
catch (IllegalAccessException e)
{}
catch ( SecurityException e)
{}
}
void hackSetupSingleClickFileBrowsingTable()
{
try
{
Field field = WebFileChooserPanel.class.getDeclaredField("fileTable");
field.setAccessible(true);//Very important, this allows the setting to work.
WebFileTable fileTable = (WebFileTable) field.get(getFileChooserPanel());
fileTable.addMouseListener(
new MouseAdapter ()
{
@Override
public void mouseClicked ( final MouseEvent e )
{
Method fireApproveAction;
try {
fireApproveAction = WebFileChooserPanel.class.getDeclaredMethod("fireApproveAction", ActionEvent.class);
if ( SwingUtilities.isLeftMouseButton ( e ) && fileTable.getSelectedRow () != -1 )
{
final File file = fileTable.getSelectedFile();
if ( !file.isDirectory () )
{
try {
fireApproveAction.setAccessible(true);
fireApproveAction.invoke(getFileChooserPanel(), new ActionEvent ( fileTable, e.getID (), "Files selected", e.getWhen (), e.getModifiers () ) );
} catch (IllegalAccessException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
} catch (NoSuchMethodException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(SignalMLFileChooser.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
);
}
catch (NoSuchFieldException e)
{}
catch (IllegalAccessException e)
{}
catch ( SecurityException e)
{}
}
public void lastDirectoryChanged() {
if (getAccessory() != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment