You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2026/08/29 23:44:24 UTC
(cayenne) 01/02: Modeler: better cgen class selector UI
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 5c7cdab254cf5b6a2a027c6323623f28955d7bee
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sat Aug 29 18:14:55 2026 -0400
Modeler: better cgen class selector UI
---
.../modeler/platform/GenericUIInitializer.java | 1 -
.../datamap/cgen/CgenArtefactSelectorPanel.java | 223 ---------------
.../datamap/cgen/CgenArtifactSelectorPanel.java | 314 +++++++++++++++++++++
.../ui/project/editor/datamap/cgen/CgenPanel.java | 8 +-
.../editor/datamap/cgen/CheckBoxHeader.java | 83 ------
5 files changed, 318 insertions(+), 311 deletions(-)
diff --git a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/platform/GenericUIInitializer.java b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/platform/GenericUIInitializer.java
index 00dc9e077..ffc993c47 100644
--- a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/platform/GenericUIInitializer.java
+++ b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/platform/GenericUIInitializer.java
@@ -38,7 +38,6 @@ public class GenericUIInitializer implements UIInitializer {
protected void overrideUIDefaults() {
Color darkGrey = new Color(203, 203, 203);
- UIManager.put("CheckBoxHeader.border", BorderFactory.createEmptyBorder(0, 15, 0, 0));
UIManager.put("CheckBoxMenuItem.selectionBackground", darkGrey);
UIManager.put("CheckBoxMenuItem.selectionForeground", Color.BLACK);
UIManager.put("MenuItem.selectionBackground", darkGrey);
diff --git a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenArtefactSelectorPanel.java b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenArtefactSelectorPanel.java
deleted file mode 100644
index 7fd7a5ea9..000000000
--- a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenArtefactSelectorPanel.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-
-package org.apache.cayenne.modeler.ui.project.editor.datamap.cgen;
-
-import org.apache.cayenne.configuration.ConfigurationNode;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.Embeddable;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.modeler.toolkit.icon.IconFactory;
-import org.apache.cayenne.modeler.toolkit.table.IconCellRenderer;
-import org.apache.cayenne.modeler.toolkit.table.TableSizer;
-import org.apache.cayenne.validation.ValidationFailure;
-import org.apache.cayenne.validation.ValidationResult;
-
-import javax.swing.Icon;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JTable;
-import javax.swing.ScrollPaneConstants;
-import javax.swing.UIManager;
-import javax.swing.table.AbstractTableModel;
-import javax.swing.table.DefaultTableCellRenderer;
-import javax.swing.table.TableColumnModel;
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * Per-class artefact selector for the cgen editor — left-side table where the user toggles
- * which classes participate in code generation, with validation icons in the rightmost column.
- */
-public class CgenArtefactSelectorPanel extends JPanel {
-
- private static final Icon ERROR_ICON = IconFactory.buildIcon("icon-error.png");
-
- private static final String[] COLUMN_HEADERS = {"", " Class", ""};
- private static final Class<?>[] COLUMN_CLASSES = {Boolean.class, JLabel.class, String.class};
-
- private final CgenPanel cgen;
- private final JTable table;
- private final CheckBoxHeader checkBoxHeader;
- private AbstractTableModel tableModel;
- private ValidationResult lastValidationResult;
-
- public CgenArtefactSelectorPanel(CgenPanel cgen) {
- this.cgen = cgen;
- this.checkBoxHeader = new CheckBoxHeader();
- this.table = new JTable();
-
- initLayout();
- }
-
- public void startup() {
- initBindings();
- classSelectedAction();
- }
-
- public JTable getTable() {
- return table;
- }
-
- private void initLayout() {
- table.setRowHeight(22);
- DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
- renderer.setBackground(UIManager.getColor("Table.selectionBackground"));
- table.getTableHeader().setDefaultRenderer(renderer);
-
- JScrollPane tablePanel = new JScrollPane(
- table,
- ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
- ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
-
- // set some minimal preferred size, so that it is smaller than other forms used in
- // the dialog... this way we get the right automated overall size
- tablePanel.setPreferredSize(new Dimension(300, 200));
-
- setLayout(new BorderLayout());
- add(tablePanel, BorderLayout.CENTER);
- }
-
- void initBindings() {
- checkBoxHeader.addActionListener(e -> checkAllAction());
-
- tableModel = new AbstractTableModel() {
- public int getRowCount() {
- return cgen.getClasses().size();
- }
-
- public int getColumnCount() {
- return COLUMN_HEADERS.length;
- }
-
- public String getColumnName(int col) {
- return COLUMN_HEADERS[col];
- }
-
- public Class<?> getColumnClass(int col) {
- return COLUMN_CLASSES[col];
- }
-
- public boolean isCellEditable(int row, int col) {
- return col == 0;
- }
-
- public Object getValueAt(int row, int col) {
- Object item = getItem(row);
- if (col == 0) return cgen.isSelected(item);
- if (col == 1) return getItemName(item);
- return getProblem(item);
- }
-
- public void setValueAt(Object value, int row, int col) {
- if (col == 0) {
- cgen.setSelected(getItem(row), (Boolean) value);
- classSelectedAction();
- }
- }
-
- private Object getItem(int row) {
- return cgen.getClasses().toArray()[row];
- }
- };
-
- table.setModel(tableModel);
-
- TableColumnModel columnModel = table.getColumnModel();
- columnModel.getColumn(0).setHeaderRenderer(checkBoxHeader);
- columnModel.getColumn(1).setCellRenderer(new IconCellRenderer());
- columnModel.getColumn(2).setCellRenderer(new IconCellRenderer());
-
- TableSizer.sizeColumns(table, Boolean.TRUE, "XXXXXXXXXXXXXXXXXXXXXXXXXX", "XX");
- }
-
- void classSelectedAction() {
- int selectedCount = cgen.getSelectedEntitiesSize()
- + cgen.getSelectedEmbeddablesSize()
- + (cgen.isDataMapSelected() ? 1 : 0);
- int totalClasses = cgen.getClasses().size();
- checkBoxHeader.setSelected(selectedCount >= totalClasses);
- cgen.updateGenerateButton();
- cgen.updateSelectedEntities();
- cgen.getStandardModeController().updateTemplateEditorButtons();
- repaint();
- }
-
- private void checkAllAction() {
- if (cgen.updateSelection(checkBoxHeader.isSelected() ? o -> true : o -> false)) {
- tableModel.fireTableDataChanged();
- cgen.updateSelectedEntities();
- cgen.updateGenerateButton();
- cgen.getStandardModeController().updateTemplateEditorButtons();
- }
- }
-
- public void validate(Collection<? extends ConfigurationNode> classes) {
- CgenValidator validator = new CgenValidator();
- this.lastValidationResult = validator.getValidationResult(classes);
- }
-
- public JLabel getProblem(Object obj) {
- String name = null;
- if (obj instanceof ObjEntity oe) {
- name = oe.getName();
- } else if (obj instanceof Embeddable emb) {
- name = emb.getClassName();
- }
-
- ValidationFailure validationFailure = null;
- if (lastValidationResult != null) {
- List<ValidationFailure> failures = lastValidationResult.getFailures(name);
- if (!failures.isEmpty()) {
- validationFailure = failures.get(0);
- }
- }
-
- JLabel labelIcon = new JLabel();
- labelIcon.setVisible(true);
- if (validationFailure != null) {
- labelIcon.setIcon(ERROR_ICON);
- labelIcon.setToolTipText(validationFailure.getDescription());
- }
- return labelIcon;
- }
-
- public JLabel getItemName(Object obj) {
- String className;
- Icon icon;
- if (obj instanceof Embeddable emb) {
- className = emb.getClassName();
- icon = IconFactory.iconForObject(new Embeddable());
- } else if (obj instanceof ObjEntity oe) {
- className = oe.getName();
- icon = IconFactory.iconForObject(new ObjEntity());
- } else {
- className = ((DataMap) obj).getName();
- icon = IconFactory.iconForObject(new DataMap());
- }
- JLabel labelIcon = new JLabel();
- labelIcon.setIcon(icon);
- labelIcon.setVisible(true);
- labelIcon.setText(className);
- return labelIcon;
- }
-}
diff --git a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenArtifactSelectorPanel.java b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenArtifactSelectorPanel.java
new file mode 100644
index 000000000..ac5d220be
--- /dev/null
+++ b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenArtifactSelectorPanel.java
@@ -0,0 +1,314 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.modeler.ui.project.editor.datamap.cgen;
+
+import org.apache.cayenne.configuration.ConfigurationNode;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.toolkit.icon.IconFactory;
+import org.apache.cayenne.validation.ValidationFailure;
+import org.apache.cayenne.validation.ValidationResult;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.Icon;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.UIManager;
+import javax.swing.border.Border;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Per-class artifact selector for the cgen editor.
+ */
+public class CgenArtifactSelectorPanel extends JPanel {
+
+ private static final Icon ERROR_ICON = IconFactory.buildIcon("icon-error.png");
+
+ private static final int ROW_HEIGHT = 22;
+ private static final Border ROW_BORDER = BorderFactory.createEmptyBorder(0, 8, 0, 8);
+
+ private final CgenPanel cgen;
+ private final JCheckBox selectAll;
+ private final JPanel classList;
+ private final List<ClassRow> rows;
+
+ private ValidationResult lastValidationResult;
+
+ public CgenArtifactSelectorPanel(CgenPanel cgen) {
+ this.cgen = cgen;
+ this.rows = new ArrayList<>();
+ this.selectAll = new JCheckBox("Select All");
+ this.classList = new JPanel();
+
+ initLayout();
+ selectAll.addActionListener(e -> selectAllAction());
+ }
+
+ /**
+ * Rebuilds the class list from the current cgen configuration and syncs the "Select All" state.
+ */
+ public void startup() {
+ refresh();
+ classSelectedAction();
+ }
+
+ /**
+ * Rebuilds the class list from the current cgen configuration. Callers that want the validation
+ * icons to be up to date must run {@link #validate(Collection)} first.
+ */
+ public void refresh() {
+ classList.removeAll();
+ rows.clear();
+
+ Map<ClassType, List<Object>> groups = new EnumMap<>(ClassType.class);
+ for (Object item : cgen.getClasses()) {
+ groups.computeIfAbsent(ClassType.of(item), t -> new ArrayList<>()).add(item);
+ }
+
+ boolean first = true;
+ for (List<Object> group : groups.values()) {
+ if (!first) {
+ classList.add(buildSeparator());
+ }
+ first = false;
+
+ for (Object item : group) {
+ ClassRow row = new ClassRow(item);
+ rows.add(row);
+ classList.add(row);
+ }
+ }
+
+ classList.revalidate();
+ classList.repaint();
+ }
+
+ private void initLayout() {
+ Color listBackground = UIManager.getColor("List.background");
+
+ classList.setLayout(new BoxLayout(classList, BoxLayout.Y_AXIS));
+ classList.setBackground(listBackground);
+
+ // keep the rows at their preferred height instead of stretching them over the viewport
+ JPanel listHolder = new JPanel(new BorderLayout());
+ listHolder.setBackground(listBackground);
+ listHolder.add(classList, BorderLayout.NORTH);
+
+ JScrollPane scrollPane = new JScrollPane(
+ listHolder,
+ ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
+ ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ scrollPane.getViewport().setBackground(listBackground);
+
+ // set some minimal preferred size, so that it is smaller than other forms used in
+ // the dialog... this way we get the right automated overall size
+ scrollPane.setPreferredSize(new Dimension(300, 200));
+
+ // white like the list below it, with a grey line on top, so that it reads as a part of
+ // the list rather than of the grey toolbar above
+ selectAll.setOpaque(false);
+ JPanel selectAllRow = new JPanel(new BorderLayout());
+ selectAllRow.setBackground(listBackground);
+ selectAllRow.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
+ selectAllRow.add(selectAll, BorderLayout.WEST);
+
+ JPanel header = new JPanel(new BorderLayout());
+ header.setBackground(listBackground);
+ header.add(buildSeparator(), BorderLayout.NORTH);
+ header.add(selectAllRow, BorderLayout.CENTER);
+ header.add(buildSeparator(), BorderLayout.SOUTH);
+
+ setLayout(new BorderLayout());
+ add(header, BorderLayout.NORTH);
+ add(scrollPane, BorderLayout.CENTER);
+ }
+
+ /**
+ * Called whenever the selection of a single class changes, either from this panel or from the
+ * outside.
+ */
+ void classSelectedAction() {
+ int selectedCount = cgen.getSelectedEntitiesSize()
+ + cgen.getSelectedEmbeddablesSize()
+ + (cgen.isDataMapSelected() ? 1 : 0);
+ selectAll.setSelected(selectedCount >= cgen.getClasses().size());
+ cgen.updateGenerateButton();
+ cgen.updateSelectedEntities();
+ cgen.getStandardModeController().updateTemplateEditorButtons();
+ repaint();
+ }
+
+ private void selectAllAction() {
+ if (cgen.updateSelection(selectAll.isSelected() ? o -> true : o -> false)) {
+ rows.forEach(ClassRow::syncSelection);
+ cgen.updateSelectedEntities();
+ cgen.updateGenerateButton();
+ cgen.getStandardModeController().updateTemplateEditorButtons();
+ }
+ }
+
+ public void validate(Collection<? extends ConfigurationNode> classes) {
+ this.lastValidationResult = new CgenValidator().getValidationResult(classes);
+ }
+
+ /**
+ * Returns the code generation problem detected for a class with the given name, or null if the
+ * class is valid.
+ */
+ public ValidationFailure getProblem(String name) {
+ if (lastValidationResult == null || name == null) {
+ return null;
+ }
+
+ List<ValidationFailure> failures = lastValidationResult.getFailures(name);
+ return failures.isEmpty() ? null : failures.get(0);
+ }
+
+ /**
+ * Creates a thin grey line that does not stretch vertically under the list's {@link BoxLayout}.
+ */
+ private static JSeparator buildSeparator() {
+ JSeparator separator = new JSeparator();
+ separator.setMaximumSize(new Dimension(Integer.MAX_VALUE, separator.getPreferredSize().height));
+ return separator;
+ }
+
+ private static String nameOf(Object item) {
+ if (item instanceof Embeddable emb) {
+ return emb.getClassName();
+ } else if (item instanceof ObjEntity oe) {
+ return oe.getName();
+ } else {
+ return ((DataMap) item).getName();
+ }
+ }
+
+ private static Icon iconOf(Object item) {
+ if (item instanceof Embeddable) {
+ return IconFactory.iconForObject(new Embeddable());
+ } else if (item instanceof ObjEntity) {
+ return IconFactory.iconForObject(new ObjEntity());
+ } else {
+ return IconFactory.iconForObject(new DataMap());
+ }
+ }
+
+ /**
+ * Kinds of classes shown in the list. Rows are grouped by type in the order declared here,
+ * regardless of the order in which the cgen configuration hands them over.
+ */
+ private enum ClassType {
+
+ DATA_MAP, OBJ_ENTITY, EMBEDDABLE;
+
+ static ClassType of(Object item) {
+ if (item instanceof ObjEntity) {
+ return OBJ_ENTITY;
+ } else if (item instanceof Embeddable) {
+ return EMBEDDABLE;
+ } else {
+ return DATA_MAP;
+ }
+ }
+ }
+
+ /**
+ * A single class in the list — a real checkbox, the class icon and name, and an optional
+ * validation problem icon. Clicking anywhere in the row toggles the checkbox.
+ */
+ private class ClassRow extends JPanel {
+
+ private final Object item;
+ private final JCheckBox checkBox;
+
+ ClassRow(Object item) {
+ super(new BorderLayout());
+
+ this.item = item;
+ this.checkBox = new JCheckBox();
+ this.checkBox.setOpaque(false);
+ this.checkBox.setSelected(cgen.isSelected(item));
+ this.checkBox.addActionListener(e -> selectionChangedAction());
+
+ JLabel name = new JLabel(nameOf(item), iconOf(item), JLabel.LEADING);
+ name.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0));
+
+ setBackground(UIManager.getColor("List.background"));
+ setBorder(ROW_BORDER);
+
+ add(checkBox, BorderLayout.WEST);
+ add(name, BorderLayout.CENTER);
+ add(buildProblemLabel(), BorderLayout.EAST);
+
+ addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ checkBox.doClick();
+ }
+ });
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ // keep the width computed from the row contents, so that a narrow panel scrolls
+ // horizontally instead of clipping long class names
+ return new Dimension(super.getPreferredSize().width, ROW_HEIGHT);
+ }
+
+ @Override
+ public Dimension getMaximumSize() {
+ return new Dimension(Integer.MAX_VALUE, ROW_HEIGHT);
+ }
+
+ void syncSelection() {
+ checkBox.setSelected(cgen.isSelected(item));
+ }
+
+ private void selectionChangedAction() {
+ cgen.setSelected(item, checkBox.isSelected());
+ classSelectedAction();
+ }
+
+ private JLabel buildProblemLabel() {
+ JLabel label = new JLabel();
+ ValidationFailure problem = getProblem(nameOf(item));
+ if (problem != null) {
+ label.setIcon(ERROR_ICON);
+ label.setToolTipText(problem.getDescription());
+ }
+ return label;
+ }
+ }
+}
diff --git a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenPanel.java b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenPanel.java
index 27844b89c..a076ab93f 100644
--- a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenPanel.java
+++ b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CgenPanel.java
@@ -75,7 +75,7 @@ public class CgenPanel extends ProjectPanel implements ObjEntityListener, Embedd
private final Set<ConfigurationNode> classes;
private final SelectionModel selectionModel;
- private final CgenArtefactSelectorPanel classesSelector;
+ private final CgenArtifactSelectorPanel classesSelector;
private final CgenConfigPanel cgenConfigPanel;
private final JButton generateButton;
@@ -108,7 +108,7 @@ public class CgenPanel extends ProjectPanel implements ObjEntityListener, Embedd
this.removeConfigBtn = new RemoveCgenConfigAction(app, configurationsComboBox, () -> cgenConfigList, () -> configuration).buildButton();
this.cgenConfigPanel = new CgenConfigPanel(session, this);
- this.classesSelector = new CgenArtefactSelectorPanel(this);
+ this.classesSelector = new CgenArtifactSelectorPanel(this);
initLayout();
initBindings();
@@ -232,9 +232,9 @@ public class CgenPanel extends ProjectPanel implements ObjEntityListener, Embedd
initConfigurationsComboBox();
setConfiguration((String) configurationsComboBox.getSelectedItem());
cgenConfigPanel.initForm(configuration);
+ classesSelector.validate(classes);
classesSelector.startup();
initFromModel = false;
- classesSelector.validate(classes);
}
/**
@@ -338,8 +338,8 @@ public class CgenPanel extends ProjectPanel implements ObjEntityListener, Embedd
selectionModel.clearAll();
setConfiguration((String) configurationsComboBox.getSelectedItem());
cgenConfigPanel.initForm(configuration);
- classesSelector.initBindings();
classesSelector.validate(classes);
+ classesSelector.refresh();
});
generatorSelectedAction();
}
diff --git a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CheckBoxHeader.java b/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CheckBoxHeader.java
deleted file mode 100644
index 5ec526e13..000000000
--- a/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/datamap/cgen/CheckBoxHeader.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-
-
-package org.apache.cayenne.modeler.ui.project.editor.datamap.cgen;
-
-import javax.swing.JCheckBox;
-import javax.swing.JTable;
-import javax.swing.UIManager;
-import javax.swing.table.JTableHeader;
-import javax.swing.table.TableCellRenderer;
-import java.awt.Component;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-
-class CheckBoxHeader extends JCheckBox implements TableCellRenderer, MouseListener {
-
- protected int column;
- protected boolean mousePressed;
-
- @Override
- public Component getTableCellRendererComponent(
- JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
-
- this.column = column;
- if (table != null) {
- JTableHeader header = table.getTableHeader();
- if (header != null) {
- header.addMouseListener(this);
- }
- }
- this.setBackground(UIManager.getColor("Table.selectionBackground"));
- setBorder(UIManager.getBorder("CheckBoxHeader.border"));
- return this;
- }
-
- @Override
- public void mouseClicked(MouseEvent e) {
- if (mousePressed) {
- mousePressed = false;
- JTableHeader header = (JTableHeader) (e.getSource());
- int columnAtPoint = header.columnAtPoint(e.getPoint());
- if (columnAtPoint == column) {
- doClick();
- }
- }
- }
-
- @Override
- public void mousePressed(MouseEvent e) {
- mousePressed = true;
- }
-
- @Override
- public void mouseReleased(MouseEvent e) {
- }
-
- @Override
- public void mouseEntered(MouseEvent e) {
- }
-
- @Override
- public void mouseExited(MouseEvent e) {
- }
-}
-
-