Skip to content

Commit

Permalink
selection of auth.method is moved to the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Jun 28, 2024
1 parent 5612566 commit de9c4d9
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 39 deletions.
4 changes: 2 additions & 2 deletions notes.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
* Server connect/disconnect actions from status bar
* Server connect/disconnect actions from the status bar
* adding selection of auth.method into the status bar
* Server Add form prepopulate details of currently selected server
* Export as Excel
* Fixing timezone bug
* Adding server and query details into a separate tab
* Adding auth.method control to the toolbar
* Any IO errors are added as Error tab (pop-up error message is used for internal bugs)
* KX errors from servers are now display with ' (not as symbol)
* Parent folder can be specified in the server form (in add and edit server)
Expand Down
3 changes: 3 additions & 0 deletions src/studio/kdb/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public String getUserPassword() throws IOException {
server.getDescription(true), server.getAuthenticationMechanism());

Class<?> clazz = AuthenticationManager.getInstance().lookup(server.getAuthenticationMechanism());
if (clazz == null) {
throw new RuntimeException("Unknown Auth.method: " + server.getAuthenticationMechanism());
}
IAuthenticationMechanism authenticationMechanism = (IAuthenticationMechanism) clazz.newInstance();

authenticationMechanism.setProperties(server.getAsProperties());
Expand Down
4 changes: 2 additions & 2 deletions src/studio/ui/EditorPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void stopClock() {
editorStatusBar.stopClock();
}

public void setSessionConnected(boolean connected) {
editorStatusBar.setSessionConnected(connected);
public void setSessionConnected(boolean connected, String authMethod) {
editorStatusBar.setSessionConnected(connected, authMethod);
}

public void setEditorStatusBarCallback(EditorStatusBarCallback callback) {
Expand Down
10 changes: 8 additions & 2 deletions src/studio/ui/EditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import studio.kdb.Config;
import studio.kdb.Server;
import studio.kdb.Session;
import studio.ui.action.QueryExecutor;
Expand Down Expand Up @@ -160,7 +161,12 @@ public void queryExecutionComplete(QueryResult queryResult) {
}

@Override
public void connect() {
public void connect(String authMethod) {
if (! server.getAuthenticationMechanism().equals(authMethod)) {
Server newServer = Config.getInstance().getServerByConnectionString(server.getConnectionString(), authMethod);
studioWindow.setServer(newServer);
}

executeQuery(QueryTask.connect());
}

Expand Down Expand Up @@ -219,7 +225,7 @@ public StudioWindow getStudioWindow() {
}

public void setSessionConnection(boolean connected) {
editorPane.setSessionConnected(connected);
editorPane.setSessionConnected(connected, server.getAuthenticationMechanism());
}

public void setStudioWindow(StudioWindow studioWindow) {
Expand Down
19 changes: 0 additions & 19 deletions src/studio/ui/StudioWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.apache.logging.log4j.Logger;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaEditorKit;
import studio.core.AuthenticationManager;
import studio.core.Studio;
import studio.kdb.*;
import studio.kdb.config.ActionOnExit;
Expand Down Expand Up @@ -76,7 +75,6 @@ public class StudioWindow extends JFrame implements WindowListener {
private boolean loading = true;

private JComboBox<String> comboServer;
private JComboBox<String> comboAuthMethod;
private JTextField txtServer;
private String lastQuery = null;
private JToolBar toolbar;
Expand Down Expand Up @@ -1070,18 +1068,6 @@ private void showServerList(boolean selectHistory) {
refreshServerListAllWindows();
}


private void selectAuthMethod() {
Object selectedItem = comboAuthMethod.getSelectedItem();
String newAuthMethod = selectedItem == null ? "" : selectedItem.toString();
if (editor.getServer().getAuthenticationMechanism().equals(newAuthMethod)) return;

Server server = CONFIG.getServerByConnectionString(txtServer.getText().trim(), newAuthMethod);
setServer(server);
refreshServer();

}

private void selectServerName() {
String selection = comboServer.getSelectedItem().toString();
if(! CONFIG.getServerNames().contains(selection)) return;
Expand Down Expand Up @@ -1133,7 +1119,6 @@ private void refreshServer() {
Server server = editor.getServer();
String name = server == Server.NO_SERVER ? "" : server.getFullName();
comboServer.setSelectedItem(name);
comboAuthMethod.getModel().setSelectedItem(server.getAuthenticationMechanism());

refreshConnectionText();
refreshActionState();
Expand All @@ -1149,9 +1134,6 @@ private void initToolbar() {
// Cut the width if it is too wide.
comboServer.setMinimumSize(new Dimension(0, 0));

comboAuthMethod = new JComboBox<>(AuthenticationManager.getInstance().getAuthenticationMechanisms());
comboAuthMethod.addActionListener(e->selectAuthMethod());

txtServer = new JTextField(32);
txtServer.setName("serverEntryTextField");
txtServer.addActionListener(e -> {
Expand All @@ -1171,7 +1153,6 @@ public void focusLost(FocusEvent e) {
toolbar.add(Box.createRigidArea(new Dimension(3,0)));
toolbar.add(new JLabel(I18n.getString("Server")));
toolbar.add(comboServer);
toolbar.add(comboAuthMethod);
toolbar.add(txtServer);

Action[] actions = new Action[] {
Expand Down
8 changes: 8 additions & 0 deletions src/studio/ui/UserAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public String getText() {
return (String)getValue(NAME);
}

public void setText(String text) {
putValue(NAME, text);
}

public void setIcon(Icon icon) {
putValue(SMALL_ICON, icon);
}

public KeyStroke getKeyStroke() {
return (KeyStroke)getValue(ACCELERATOR_KEY);
}
Expand Down
77 changes: 64 additions & 13 deletions src/studio/ui/statusbar/EditorStatusBar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package studio.ui.statusbar;

import studio.core.AuthenticationManager;
import studio.ui.MinSizeLabel;
import studio.ui.UserAction;
import studio.ui.Util;
Expand All @@ -17,16 +18,22 @@ public class EditorStatusBar extends StatusBar {
private final Timer timer;
private long clock;
private boolean sessionConnected = false;
private String authMethod = "";
private EditorStatusBarCallback editorStatusBarCallback = null;

private UserAction actionConnect;
private String[] knonwAuthMethods;
private UserAction[] actionsConnect;
private UserAction actionUnkownAuthConnect = null;

private UserAction actionDisconnect;

private final static Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
private final static String CONNECTED = "Connected";
private final static String DISCONNECTED = "Disconnected";

public EditorStatusBar() {
initActions();

lblConnection = new MinSizeLabel("");
lblConnection.setHorizontalAlignment(JLabel.CENTER);
lblConnection.setMinimumWidth("1:00:00", CONNECTED, DISCONNECTED);
Expand All @@ -38,11 +45,15 @@ public void mousePressed(MouseEvent e) {
if (editorStatusBarCallback == null) return;

JPopupMenu menu = new JPopupMenu();
if (sessionConnected) {
menu.add(actionDisconnect);
} else {
menu.add(actionConnect);
JMenuItem menuItem = menu.add(actionDisconnect);
menuItem.setDisabledIcon(menuItem.getIcon());
menu.addSeparator();
if (actionUnkownAuthConnect != null) menu.add(actionUnkownAuthConnect);
for (Action action: actionsConnect) {
menuItem = menu.add(action);
menuItem.setDisabledIcon(menuItem.getIcon());
}

menu.show(lblConnection, e.getX(), e.getY());
}
});
Expand All @@ -51,18 +62,24 @@ public void mousePressed(MouseEvent e) {
refreshConnectedLabel();
}

public void setEditorStatusBarCallback(EditorStatusBarCallback editorStatusBarCallback) {
this.editorStatusBarCallback = editorStatusBarCallback;
if (editorStatusBarCallback == null) return;

actionConnect = UserAction.create("Connect", Util.CHECK_ICON,
e -> this.editorStatusBarCallback.connect()
);
private void initActions() {
knonwAuthMethods = AuthenticationManager.getInstance().getAuthenticationMechanisms();
actionsConnect = new UserAction[knonwAuthMethods.length];
for (int index = 0; index < knonwAuthMethods.length; index++) {
String auth = knonwAuthMethods[index];
actionsConnect[index] = UserAction.create(auth,
auth.equals(authMethod) ? Util.CHECK_ICON : Util.BLANK_ICON,
e -> this.editorStatusBarCallback.connect(auth) );
}
actionUnkownAuthConnect = null;

actionDisconnect = UserAction.create("Disconnect", Util.ERROR_SMALL_ICON,
e -> this.editorStatusBarCallback.disconnect()
);
}

public void setEditorStatusBarCallback(EditorStatusBarCallback editorStatusBarCallback) {
this.editorStatusBarCallback = editorStatusBarCallback;
}

public void startClock() {
Expand All @@ -75,13 +92,47 @@ public void stopClock() {
refreshConnectedLabel();
}

public void setSessionConnected(boolean connected) {
public void setSessionConnected(boolean connected, String authMethod) {
sessionConnected = connected;
this.authMethod = authMethod;

refreshConnectedLabel();
}

private void refreshConnectedLabel() {
lblConnection.setText(sessionConnected ? CONNECTED : DISCONNECTED);
if (sessionConnected) {
lblConnection.setToolTipText("Connected with '"+authMethod+"'");
} else {
lblConnection.setToolTipText("Disconnected");
}

boolean found = false;
for (int index = 0; index < knonwAuthMethods.length; index++) {
UserAction action = actionsConnect[index];
String auth = knonwAuthMethods[index];
if (auth.equals(authMethod)) {
action.setIcon(Util.CHECK_ICON);
action.setText(authMethod + (sessionConnected ? " (Connected)" : "") );
action.setEnabled(!sessionConnected);
found = true;
} else {
action.setIcon(Util.BLANK_ICON);
action.setText(auth);
action.setEnabled(true);
}
}

if (found) {
actionUnkownAuthConnect = null;
} else {
actionUnkownAuthConnect = UserAction.create(authMethod + (sessionConnected ? " (Connected)" : ""), Util.CHECK_ICON,
e -> this.editorStatusBarCallback.connect(authMethod) );
}

actionDisconnect.setText(sessionConnected ? "Disconnect" : "(Disconnected)");
actionDisconnect.setEnabled(sessionConnected);

}

private void timerClockAction(ActionEvent event) {
Expand Down
2 changes: 1 addition & 1 deletion src/studio/ui/statusbar/EditorStatusBarCallback.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package studio.ui.statusbar;

public interface EditorStatusBarCallback {
void connect();
void connect(String authMethod);
void disconnect();
}

0 comments on commit de9c4d9

Please sign in to comment.