|
|
|
package com.fr.plugin.file.submit.oss.ui;
|
|
|
|
|
|
|
|
import com.fr.design.editor.ValueEditorPane;
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox;
|
|
|
|
import com.fr.design.gui.ilable.UILabel;
|
|
|
|
import com.fr.design.gui.itableeditorpane.UITableEditAction;
|
|
|
|
import com.fr.design.gui.itableeditorpane.UITableModelAdapter;
|
|
|
|
import com.fr.design.i18n.Toolkit;
|
|
|
|
import com.fr.general.GeneralUtils;
|
|
|
|
import com.fr.plugin.file.submit.oss.fun.OssSubmitTarget;
|
|
|
|
import com.fr.plugin.file.submit.oss.fun.OssVariableValue;
|
|
|
|
import com.fr.plugin.oss.universal.config.OssUniversalConfig;
|
|
|
|
import com.fr.stable.StringUtils;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import javax.swing.event.CellEditorListener;
|
|
|
|
import javax.swing.event.ChangeEvent;
|
|
|
|
import javax.swing.table.DefaultTableCellRenderer;
|
|
|
|
import javax.swing.table.TableCellEditor;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
|
|
|
public class OssSubmitPathTableModel extends UITableModelAdapter<OssSubmitTarget> {
|
|
|
|
|
|
|
|
public OssSubmitPathTableModel() {
|
|
|
|
super(new String[]{
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_Bucket_Name"),
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_Directory"),
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_File"),
|
|
|
|
com.fr.design.i18n.Toolkit.i18nText("Plugin-File_Submit_Oss_File_Name")});
|
|
|
|
|
|
|
|
this.setColumnClass(new Class[]{BucketEditor.class, DirectoryEditor.class, FileSelectEditor.class, FileNameEditor.class});
|
|
|
|
|
|
|
|
this.setDefaultEditor(BucketEditor.class, new BucketEditor());
|
|
|
|
this.setDefaultRenderer(BucketEditor.class, new SimpleRenderer());
|
|
|
|
|
|
|
|
this.setDefaultEditor(DirectoryEditor.class, new DirectoryEditor());
|
|
|
|
this.setDefaultRenderer(DirectoryEditor.class, new CurrentValueRenderer());
|
|
|
|
|
|
|
|
this.setDefaultEditor(FileSelectEditor.class, new FileSelectEditor());
|
|
|
|
this.setDefaultRenderer(FileSelectEditor.class, new CurrentValueRenderer());
|
|
|
|
|
|
|
|
this.setDefaultEditor(FileNameEditor.class, new FileNameEditor());
|
|
|
|
this.setDefaultRenderer(FileNameEditor.class, new CurrentValueRenderer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getValueAt(final int row, final int column) {
|
|
|
|
final OssSubmitTarget target = this.getList().get(row);
|
|
|
|
switch (column) {
|
|
|
|
case 0: {
|
|
|
|
return target.getBucket();
|
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
return target.getDirectory() == null ? null : target.getDirectory().getValue();
|
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
return target.getFile() == null ? null : target.getFile().getValue();
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
return target.getName() == null ? null : target.getName().getValue();
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCellEditable(final int row, final int column) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UITableEditAction[] createAction() {
|
|
|
|
return new UITableEditAction[]{
|
|
|
|
new AddPathAction(),
|
|
|
|
new UITableModelAdapter.DeleteAction(),
|
|
|
|
new UITableModelAdapter.MoveUpAction(),
|
|
|
|
new UITableModelAdapter.MoveDownAction()};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addPath() {
|
|
|
|
this.addRow(new OssSubmitTarget());
|
|
|
|
this.fireTableDataChanged();
|
|
|
|
this.table.getSelectionModel().setSelectionInterval(this.table.getRowCount() - 1, this.table.getRowCount() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class BucketEditor extends AbstractCellEditor implements TableCellEditor {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private UIComboBox bucketComboBox;
|
|
|
|
|
|
|
|
public BucketEditor() {
|
|
|
|
bucketComboBox = new UIComboBox(OssUniversalConfig.getInstance().getArrayBuckets());
|
|
|
|
this.addCellEditorListener(new CellEditorListener() {
|
|
|
|
@Override
|
|
|
|
public void editingCanceled(final ChangeEvent changeEvent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void editingStopped(final ChangeEvent changeEvent) {
|
|
|
|
if (table.getSelectedRow() == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
|
|
|
|
submitTarget.setBucket(GeneralUtils.objectToString(getCellEditorValue()));
|
|
|
|
fireTableDataChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
|
|
|
|
bucketComboBox.setSelectedItem(o);
|
|
|
|
return this.bucketComboBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getCellEditorValue() {
|
|
|
|
return this.bucketComboBox.getSelectedItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class DirectoryEditor extends AbstractCellEditor implements TableCellEditor {
|
|
|
|
private ValueEditorPane textField;
|
|
|
|
|
|
|
|
public DirectoryEditor() {
|
|
|
|
this.textField = Editors.createValueEditorPane();
|
|
|
|
this.addCellEditorListener(new CellEditorListener() {
|
|
|
|
@Override
|
|
|
|
public void editingCanceled(final ChangeEvent changeEvent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void editingStopped(final ChangeEvent changeEvent) {
|
|
|
|
if (table.getSelectedRow() == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
|
|
|
|
submitTarget.setDirectory(new OssVariableValue(getCellEditorValue()));
|
|
|
|
fireTableDataChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
|
|
|
|
this.textField.populate((o == null) ? StringUtils.EMPTY : o);
|
|
|
|
return this.textField;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getCellEditorValue() {
|
|
|
|
return this.textField.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class FileSelectEditor extends AbstractCellEditor implements TableCellEditor {
|
|
|
|
private ValueEditorPane textField;
|
|
|
|
|
|
|
|
public FileSelectEditor() {
|
|
|
|
this.textField = Editors.createValueEditorPane();
|
|
|
|
this.addCellEditorListener(new CellEditorListener() {
|
|
|
|
@Override
|
|
|
|
public void editingCanceled(final ChangeEvent changeEvent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void editingStopped(final ChangeEvent changeEvent) {
|
|
|
|
if (table.getSelectedRow() == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
|
|
|
|
submitTarget.setFile(new OssVariableValue(getCellEditorValue()));
|
|
|
|
fireTableDataChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
|
|
|
|
this.textField.populate((o == null) ? StringUtils.EMPTY : o);
|
|
|
|
return this.textField;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getCellEditorValue() {
|
|
|
|
return this.textField.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class FileNameEditor extends AbstractCellEditor implements TableCellEditor {
|
|
|
|
private ValueEditorPane textField;
|
|
|
|
|
|
|
|
public FileNameEditor() {
|
|
|
|
this.textField = Editors.createValueEditorPane();
|
|
|
|
this.addCellEditorListener(new CellEditorListener() {
|
|
|
|
@Override
|
|
|
|
public void editingCanceled(final ChangeEvent changeEvent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void editingStopped(final ChangeEvent changeEvent) {
|
|
|
|
if (table.getSelectedRow() == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final OssSubmitTarget submitTarget = getList().get(table.getSelectedRow());
|
|
|
|
submitTarget.setName(new OssVariableValue(getCellEditorValue()));
|
|
|
|
fireTableDataChanged();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component getTableCellEditorComponent(final JTable table, final Object o, final boolean b, final int n, final int n2) {
|
|
|
|
this.textField.populate((o == null) ? StringUtils.EMPTY : o);
|
|
|
|
return this.textField;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getCellEditorValue() {
|
|
|
|
return this.textField.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SimpleRenderer extends DefaultTableCellRenderer {
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
|
this.setText(GeneralUtils.objectToString(value));
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class CurrentValueRenderer extends DefaultTableCellRenderer {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private ValueEditorPane editor;
|
|
|
|
private UILabel disableLabel;
|
|
|
|
|
|
|
|
public CurrentValueRenderer() {
|
|
|
|
this(Editors.createValueEditorPane());
|
|
|
|
}
|
|
|
|
|
|
|
|
public CurrentValueRenderer(ValueEditorPane valueEditorPane) {
|
|
|
|
disableLabel = new UILabel(Toolkit.i18nText("Plugin-File_Submit_Oss_Disable"));
|
|
|
|
disableLabel.setForeground(Color.pink);
|
|
|
|
disableLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
|
|
|
|
|
|
|
editor = valueEditorPane;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
|
if (table.isCellEditable(row, column)) {
|
|
|
|
if (value == null) {
|
|
|
|
editor.populate(StringUtils.EMPTY);
|
|
|
|
} else {
|
|
|
|
if (value instanceof OssVariableValue) {
|
|
|
|
editor.populate(((OssVariableValue) value).getValue());
|
|
|
|
} else {
|
|
|
|
editor.populate(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return editor;
|
|
|
|
} else {
|
|
|
|
return disableLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class AddPathAction extends UITableModelAdapter.AddTableRowAction {
|
|
|
|
public AddPathAction() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void actionPerformed(final ActionEvent actionEvent) {
|
|
|
|
super.actionPerformed(actionEvent);
|
|
|
|
OssSubmitPathTableModel.this.addPath();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|