Line 1... |
Line 1... |
1 |
/*
|
1 |
/*
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 |
*
|
3 |
*
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
5 |
*
|
5 |
*
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
9 |
* language governing permissions and limitations under the License.
|
9 |
* language governing permissions and limitations under the License.
|
Line 33... |
Line 33... |
33 |
import org.openconcerto.sql.view.list.IListeAction;
|
33 |
import org.openconcerto.sql.view.list.IListeAction;
|
34 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
34 |
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
|
35 |
import org.openconcerto.sql.view.list.ITableModel;
|
35 |
import org.openconcerto.sql.view.list.ITableModel;
|
36 |
import org.openconcerto.sql.view.list.RowAction;
|
36 |
import org.openconcerto.sql.view.list.RowAction;
|
37 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
37 |
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
|
- |
|
38 |
import org.openconcerto.sql.view.list.action.SQLRowValuesAction;
|
38 |
import org.openconcerto.sql.view.search.SearchListComponent;
|
39 |
import org.openconcerto.sql.view.search.SearchListComponent;
|
39 |
import org.openconcerto.ui.ContinuousButtonModel;
|
40 |
import org.openconcerto.ui.ContinuousButtonModel;
|
40 |
import org.openconcerto.ui.FrameUtil;
|
41 |
import org.openconcerto.ui.FrameUtil;
|
41 |
import org.openconcerto.ui.SwingThreadUtils;
|
42 |
import org.openconcerto.ui.SwingThreadUtils;
|
42 |
import org.openconcerto.ui.component.JRadioButtons.JStringRadioButtons;
|
43 |
import org.openconcerto.ui.component.JRadioButtons.JStringRadioButtons;
|
Line 67... |
Line 68... |
67 |
import java.sql.SQLException;
|
68 |
import java.sql.SQLException;
|
68 |
import java.util.Arrays;
|
69 |
import java.util.Arrays;
|
69 |
import java.util.Collections;
|
70 |
import java.util.Collections;
|
70 |
import java.util.HashMap;
|
71 |
import java.util.HashMap;
|
71 |
import java.util.HashSet;
|
72 |
import java.util.HashSet;
|
- |
|
73 |
import java.util.IdentityHashMap;
|
72 |
import java.util.List;
|
74 |
import java.util.List;
|
73 |
import java.util.Map;
|
75 |
import java.util.Map;
|
74 |
import java.util.Set;
|
76 |
import java.util.Set;
|
75 |
import java.util.prefs.Preferences;
|
77 |
import java.util.prefs.Preferences;
|
76 |
|
78 |
|
Line 107... |
Line 109... |
107 |
return getConfigFile(elem, c, null);
|
109 |
return getConfigFile(elem, c, null);
|
108 |
}
|
110 |
}
|
109 |
|
111 |
|
110 |
static public final File getConfigFile(final SQLElement elem, final Class<? extends Container> c, final String variant) {
|
112 |
static public final File getConfigFile(final SQLElement elem, final Class<? extends Container> c, final String variant) {
|
111 |
final String suffix = StringUtils.isEmpty(variant, true) ? "" : "-" + variant;
|
113 |
final String suffix = StringUtils.isEmpty(variant, true) ? "" : "-" + variant;
|
112 |
return getConfigFile(c, elem.getCode() + suffix);
|
114 |
return getConfigFile(IListFrame.getConfDir(elem), c, elem.getCode() + suffix);
|
113 |
}
|
115 |
}
|
114 |
|
116 |
|
115 |
static public final File getConfigFile(final Class<? extends Container> c, String code) {
|
117 |
static public final File getConfigFile(final Class<? extends Container> c, String code) {
|
116 |
final Configuration conf = Configuration.getInstance();
|
118 |
return getConfigFile(IListFrame.getConfDir(null), c, code);
|
- |
|
119 |
}
|
- |
|
120 |
|
- |
|
121 |
static public final File getConfigFile(final File rootDir, final Class<? extends Container> c, String code) {
|
117 |
if (conf == null)
|
122 |
if (rootDir == null)
|
118 |
return null;
|
123 |
return null;
|
119 |
|
124 |
|
120 |
final File structFile = new File(conf.getConfDir(), "jtableState-" + FILE_STRUCT_VERSION);
|
125 |
final File structFile = new File(rootDir, "jtableState-" + FILE_STRUCT_VERSION);
|
121 |
return new File(structFile, c.getSimpleName() + File.separator + IListFrame.getConfigFileName(code));
|
126 |
return new File(structFile, c.getSimpleName() + File.separator + IListFrame.getConfigFileName(code));
|
122 |
}
|
127 |
}
|
123 |
|
128 |
|
124 |
public static enum FrameMode {
|
129 |
public static enum FrameMode {
|
125 |
NO_FRAME, READ_ONLY_FRAME, READ_WRITE_FRAME;
|
130 |
NO_FRAME, READ_ONLY_FRAME, READ_WRITE_FRAME;
|
Line 165... |
Line 170... |
165 |
protected JButton buttonClone;
|
170 |
protected JButton buttonClone;
|
166 |
protected JButton saveBtn;
|
171 |
protected JButton saveBtn;
|
167 |
private JButton buttonPlus;
|
172 |
private JButton buttonPlus;
|
168 |
private JButton buttonMoins;
|
173 |
private JButton buttonMoins;
|
169 |
protected final JPanel searchPanel = new JPanel(new GridBagLayout());
|
174 |
protected final JPanel searchPanel = new JPanel(new GridBagLayout());
|
- |
|
175 |
|
170 |
private static final JButton createBtn(Icon i) {
|
176 |
private static final JButton createBtn(Icon i) {
|
171 |
final JButton res = new JButton(i);
|
177 |
final JButton res = new JButton(i);
|
172 |
res.setMargin(new Insets(1, 1, 1, 1));
|
178 |
res.setMargin(new Insets(1, 1, 1, 1));
|
173 |
res.setModel(new ContinuousButtonModel(300));
|
179 |
res.setModel(new ContinuousButtonModel(300));
|
174 |
res.setBorder(BorderFactory.createEmptyBorder());
|
180 |
res.setBorder(BorderFactory.createEmptyBorder());
|
Line 217... |
Line 223... |
217 |
throw new IllegalArgumentException("Different tables : " + elem.getTable() + " != " + list.getSource().getPrimaryTable());
|
223 |
throw new IllegalArgumentException("Different tables : " + elem.getTable() + " != " + list.getSource().getPrimaryTable());
|
218 |
if (list.getConfigFile() == null)
|
224 |
if (list.getConfigFile() == null)
|
219 |
list.setConfigFile(config);
|
225 |
list.setConfigFile(config);
|
220 |
}
|
226 |
}
|
221 |
this.liste = list;
|
227 |
this.liste = list;
|
- |
|
228 |
final Map<SQLRowValuesAction, IListeAction> actionsMap = new IdentityHashMap<>();
|
222 |
final IClosure<ListChangeIndex<IListeAction>> l = new IClosure<ListChangeIndex<IListeAction>>() {
|
229 |
final IClosure<ListChangeIndex<SQLRowValuesAction>> l = new IClosure<ListChangeIndex<SQLRowValuesAction>>() {
|
223 |
@Override
|
230 |
@Override
|
224 |
public void executeChecked(ListChangeIndex<IListeAction> input) {
|
231 |
public void executeChecked(ListChangeIndex<SQLRowValuesAction> input) {
|
- |
|
232 |
SwingThreadUtils.invoke(() -> {
|
225 |
getListe().removeIListeActions(input.getItemsRemoved());
|
233 |
for (final SQLRowValuesAction a : input.getItemsRemoved()) {
|
226 |
getListe().addIListeActions(input.getItemsAdded());
|
234 |
final IListeAction la = actionsMap.remove(a);
|
- |
|
235 |
if (la != null)
|
- |
|
236 |
getListe().removeIListeAction(la);
|
- |
|
237 |
}
|
- |
|
238 |
actionsMap.putAll(getListe().addRowValuesActions(getElement().getRowValuesActions()));
|
- |
|
239 |
});
|
227 |
}
|
240 |
}
|
228 |
};
|
241 |
};
|
229 |
// remove listener if non displayable since getElement() never dies
|
242 |
// remove listener if non displayable since getElement() never dies
|
230 |
this.addHierarchyListener(new HierarchyListener() {
|
243 |
this.addHierarchyListener(new HierarchyListener() {
|
- |
|
244 |
@Override
|
231 |
public void hierarchyChanged(HierarchyEvent e) {
|
245 |
public void hierarchyChanged(HierarchyEvent e) {
|
232 |
if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0)
|
246 |
if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0)
|
233 |
if (isDisplayable()) {
|
247 |
if (isDisplayable()) {
|
- |
|
248 |
assert actionsMap.isEmpty();
|
234 |
getListe().addIListeActions(getElement().getRowActions());
|
249 |
actionsMap.putAll(getListe().addRowValuesActions(getElement().getRowValuesActions()));
|
235 |
getElement().addRowActionsListener(l);
|
250 |
getElement().addRowActionsListener(l);
|
236 |
} else {
|
251 |
} else {
|
237 |
getElement().removeRowActionsListener(l);
|
252 |
getElement().removeRowActionsListener(l);
|
238 |
getListe().removeIListeActions(getElement().getRowActions());
|
253 |
getListe().removeIListeActions(actionsMap.values());
|
- |
|
254 |
actionsMap.clear();
|
239 |
}
|
255 |
}
|
240 |
}
|
256 |
}
|
241 |
});
|
257 |
});
|
242 |
|
258 |
|
243 |
this.displayRowAction = new PredicateRowAction(new AbstractAction(TM.tr("display")) {
|
259 |
this.displayRowAction = new PredicateRowAction(new AbstractAction(TM.tr("display")) {
|
Line 783... |
Line 799... |
783 |
btn.setEnabled(finalOK);
|
799 |
btn.setEnabled(finalOK);
|
784 |
}
|
800 |
}
|
785 |
}
|
801 |
}
|
786 |
|
802 |
|
787 |
private boolean isRO() {
|
803 |
private boolean isRO() {
|
788 |
final SQLRowAccessor r = getListe().getSelectedRow();
|
804 |
final SQLRowAccessor r = getListe().getSelectedRowAccessor();
|
789 |
return r != null && SQLComponent.isReadOnly(r);
|
805 |
return r != null && SQLComponent.isReadOnly(r);
|
790 |
}
|
806 |
}
|
791 |
}
|
807 |
}
|
792 |
|
808 |
|
793 |
protected final void updateOrderButtons() {
|
809 |
protected final void updateOrderButtons() {
|