Skip to content

Commit

Permalink
Introduction of the "ConnectionType" concept.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisser committed Nov 8, 2023
1 parent 4801019 commit 6def1b0
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
7 changes: 0 additions & 7 deletions src/main/engine/net/sf/jailer/JailerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,3 @@ public static void main(String[] args) {
}

}


// TODO
// TODO DBConDialog: copy/import creditials mit "Verbindungstyp"

// TODO
// TODO DBConDialog: copy/import creditials: 1. tooltip + "connection-credentials"? 2. tooltip: "paste here"? ???
4 changes: 2 additions & 2 deletions src/main/gui/net/sf/jailer/ui/DataModelManagerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,8 @@ private void initRestoreLastSessionButton() {
}

String bgc = "";
if (connectionInfo != null && connectionInfo.getConnectionType().getBg1() != null) {
bgc = Integer.toHexString(connectionInfo.getConnectionType().getBg1().getRGB() & 0xffffff);
if (connectionInfo != null && connectionInfo.getConnectionType().getBackground() != null) {
bgc = Integer.toHexString(connectionInfo.getConnectionType().getBackground().getRGB() & 0xffffff);
while (bgc.length() < 6) {
bgc = "0" + bgc;
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/gui/net/sf/jailer/ui/DbConnectionDetailsEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
Component render = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof ConnectionType && render instanceof JLabel) {
if (!isSelected) {
Color b1 = ((ConnectionType) value).getBg1();
Color b1 = ((ConnectionType) value).getBackground();
render.setBackground(b1 == null? dbg : b1);
render.setForeground(Color.black);
}
Expand All @@ -347,7 +347,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
});
typeComboBox.addItemListener(e -> {
if (typeComboBox.getSelectedItem() != null) {
Color b1 = ((ConnectionType) typeComboBox.getSelectedItem()).getBg1();
Color b1 = ((ConnectionType) typeComboBox.getSelectedItem()).getBackground();
typeComboBox.setBackground(b1 == null? dbg : b1);
}
});
Expand Down Expand Up @@ -1580,6 +1580,7 @@ private void exportCBButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
String separator = Arrays.stream(SEPARATORS).filter(sep -> !rawContent.contains(sep)).findAny().orElseGet(() -> null);
if (separator != null) {
content = separator + Arrays.stream(textFields).map(field -> field.getText()).collect(Collectors.joining(separator)) + separator;
content += typeComboBox.getSelectedItem() + separator;
StringSelection contents = new StringSelection(content);
UIUtil.setClipboardContent(contents);
showFeedback("credentials copied to clipboard");
Expand All @@ -1605,9 +1606,16 @@ private void importCBButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
String separator = content.substring(0, 1);
content = content.substring(1);
String[] fields = content.split(Pattern.quote(separator));
for (int i = 0; i < textFields.length && i < fields.length; ++i) {
int i;
for (i = 0; i < textFields.length && i < fields.length; ++i) {
textFields[i].setText(fields[i]);
}
if (i >= 0 && i < fields.length) {
String tField = fields[i].trim();
Arrays.stream(ConnectionType.values())
.filter(t -> t.displayName.equals(tField)).findAny()
.ifPresent(t -> typeComboBox.setSelectedItem(t));
}
String newName = createNewName(user.getText(), dbUrl.getText());
if (newName.replaceFirst("\\s*\\(\\d+\\)$", "").equals(alias.getText().replaceFirst("\\s*\\(\\d+\\)$", ""))) {
nameContent = alias.getText();
Expand Down
73 changes: 39 additions & 34 deletions src/main/gui/net/sf/jailer/ui/DbConnectionDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.ComponentEvent;
Expand All @@ -42,7 +43,9 @@
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.stream.Collectors;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
Expand All @@ -52,6 +55,8 @@
import javax.swing.RowSorter;
import javax.swing.RowSorter.SortKey;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
Expand Down Expand Up @@ -95,42 +100,26 @@ public class DbConnectionDialog extends javax.swing.JDialog {
public enum ConnectionType {
Development("Development database") {
@Override
public Color getBg1() {
return null;
}
@Override
public Color getBg2() {
public Color getBackground() {
return null;
}
},
Test("Test (QA) database") {
@Override
public Color getBg1() {
return new Color(255, 255, 200);
}
@Override
public Color getBg2() {
return new Color(255, 255, 220);
public Color getBackground() {
return new Color(180, 255, 180);
}
},
Staging("Staging database") {
@Override
public Color getBg1() {
return new Color(255, 225, 200);
}
@Override
public Color getBg2() {
return new Color(255, 225, 220);
public Color getBackground() {
return new Color(255, 255, 160);
}
},
Production("Production database") {
@Override
public Color getBg1() {
return new Color(255, 190, 190);
}
@Override
public Color getBg2() {
return new Color(255, 180, 180);
public Color getBackground() {
return new Color(255, 200, 200);
}
};

Expand All @@ -143,12 +132,7 @@ public String toString() {
return displayName;
}

public abstract Color getBg1();
public abstract Color getBg2();
// TODO
// TODO bg2 weg oder heller für tabelle?
// TODO farben zu ähnlich?
// TODO in tabelle die ersten beiden Spalten bei Selection weiterhin in bg-farbe?
public abstract Color getBackground();
public final String displayName;
}

Expand Down Expand Up @@ -535,9 +519,21 @@ public Component getTableCellRendererComponent(
connectionType = connectionList.get(selectedRowIndex).getConnectionType();
}

if (connectionType != null && connectionType.getBg1() != null) {
bg = connectionType.getBg1();
// bg = (row % 2 == 0) ? connectionType.getBg1() : connectionType.getBg2();
if (connectionType != null && connectionType.getBackground() != null) {
bg = connectionType.getBackground();
if (isSelected) {
Border lb = new LineBorder(new Color(160, 200, 255), 2, false) {
@Override
public Insets getBorderInsets(Component c, Insets insets) {
return new Insets(0, 0, 0, 0);
}
};
if (((JLabel) render).getBorder() == null) {
((JLabel) render).setBorder(lb);
} else {
((JLabel) render).setBorder(BorderFactory.createCompoundBorder(lb, ((JLabel) render).getBorder()));
}
}
((JLabel) render).setToolTipText("<html>" + UIUtil.toHTMLFragment(((JLabel) render).getToolTipText(), 0) + "<br><hr>" + connectionType.displayName + "</html>");
}

Expand Down Expand Up @@ -1667,8 +1663,17 @@ public void doDelete(ConnectionInfo ci) {
}

public ConnectionType retrieveConnectionType(ConnectionInfo ci) {
return connectionList.stream().filter(c -> ci.url.equals(c.url) && ci.user.equals(c.user))
.map(c -> c.getConnectionType()).findAny().orElseGet(() -> ConnectionType.Development);
List<ConnectionType> result = connectionList.stream().filter(c -> ci.url.equals(c.url) && ci.user.equals(c.user))
.map(c -> c.getConnectionType()).collect(Collectors.toList());
if (result.size() == 1) {
return result.get(0);
}
result = connectionList.stream().filter(c -> ci.alias.equals(c.alias))
.map(c -> c.getConnectionType()).collect(Collectors.toList());
if (result.size() >= 1) {
return result.get(0);
}
return ConnectionType.Development;
}

public interface ConnectionTypeChangeListener {
Expand Down
4 changes: 2 additions & 2 deletions src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void onConnectionTypeChange() {
if (lastConnectionInfo != null && dbConnectionDialog != null) {
lastConnectionInfo.setConnectionType(connectionType = dbConnectionDialog.retrieveConnectionType(lastConnectionInfo));
}
Color bg = connectionType != null ? connectionType.getBg1() : null;
Color bg = connectionType != null ? connectionType.getBackground() : null;
if (bg != null) {
extractionModelEditor.connectivityState.setBackground(bg);
extractionModelEditor.legende2.setBackground(bg);
Expand Down Expand Up @@ -368,7 +368,7 @@ private String getConnectivityStateToolTip() {
private String getConnectivityStateToolTip(ConnectionInfo connectionInfo) {
if (connectionInfo != null) {
String url = connectionInfo.url;
if (connectionInfo.getConnectionType().getBg1() != null) {
if (connectionInfo.getConnectionType().getBackground() != null) {
url = "<html>" + UIUtil.toHTMLFragment(url, 0) + "<br><hr>" + connectionInfo.getConnectionType().displayName + "</html>";
}
return url;
Expand Down
10 changes: 4 additions & 6 deletions src/main/gui/net/sf/jailer/ui/databrowser/DataBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ public int getIconWidth() {
}
};
}
Color bgCol = node.getConnectionType().getBg1();
Color bgCol = node.getConnectionType().getBackground();

if (bgCol != null && !sel) {
((JLabel) render).setBackground(bgCol);
Expand Down Expand Up @@ -1567,7 +1567,7 @@ public void mouseMoved(MouseEvent e) {
"<html><b>" + UIUtil.toHTMLFragment(ciRender(ci), 0) + "</b><br>" +
(ci.user != null && ci.user.length() > 0? UIUtil.toHTMLFragment(ci.user, 0) + "<br>" : "") +
UIUtil.toHTMLFragment(ci.url, 0) +
(ci.getConnectionType().getBg1() != null? "<br>" + ci.getConnectionType().displayName : "")
(ci.getConnectionType().getBackground() != null? "<br>" + ci.getConnectionType().displayName : "")
);
return;
}
Expand All @@ -1594,8 +1594,6 @@ public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
connect(DataBrowser.this, o);
} else {
// TODO
// TODO check if necessary
dbConnectionDialog.select((ConnectionInfo) o);
}
}
Expand Down Expand Up @@ -2076,7 +2074,7 @@ public void onConnectionTypeChange() {
if (lastConnectionInfo != null && dbConnectionDialog != null) {
lastConnectionInfo.setConnectionType(connectionType = dbConnectionDialog.retrieveConnectionType(lastConnectionInfo));
}
Color bg = connectionType != null ? connectionType.getBg1() : null;
Color bg = connectionType != null ? connectionType.getBackground() : null;
if (bg == null) {
jToolBar1.setToolTipText(null);
jToolBar1.setBackground(origTBBG);
Expand Down Expand Up @@ -2125,7 +2123,7 @@ public void updateStatusBar() {
origL2Op = legende2.isOpaque();
}
onConnectionTypeChange();
Color bg = connectionType != null ? connectionType.getBg1() : null;
Color bg = connectionType != null ? connectionType.getBackground() : null;

String dburl = connection != null ? (connection.url) : " ";
String dbmsLogoURL = UIUtil.getDBMSLogoURL(dburl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4373,7 +4373,7 @@ public void updateConnectionType(ConnectionType connectionType) {
origTBBG = jToolBar1.getBackground();
origP5BG = jPanel5.getBackground();
}
Color bg = connectionType == null? null : connectionType.getBg1();
Color bg = connectionType == null? null : connectionType.getBackground();
if (bg == null) {
jToolBar1.setBackground(origTBBG);
jPanel5.setBackground(origP5BG);
Expand Down

0 comments on commit 6def1b0

Please sign in to comment.