From 3dff9bf8b05cb11c45f67c95494c42759eae1478 Mon Sep 17 00:00:00 2001 From: "S.Homburg" Date: Mon, 3 Oct 2022 18:16:38 +0200 Subject: [PATCH] manual creation of toolwindow content --- CHANGELOG.md | 9 +- .../querytester/QueryTesterConstants.java | 2 +- .../QueryTesterToolWindowFactory.java | 26 +- .../events/CheckServerConnectionEvent.java | 28 ++ .../events/CheckedServerConnectionEvent.java | 28 ++ .../events/ConnectionAddedEvent.java | 32 +- .../events/ConnectionChangedEvent.java | 32 +- .../events/ConnectionRemovedEvent.java | 32 +- .../ConnectionSelectionChangedEvent.java | 8 +- .../events/StartQueryExecutionEvent.java | 10 +- .../ConnectionConfigurationComboBoxModel.java | 18 +- .../models/ConnectionSettings.java | 136 +++++++++ .../models/FontFaceComboBoxModel.java | 25 +- .../querytester/models/SettingsState.java | 4 - .../renderer/ComboBoxToolTipRenderer.java | 40 +++ .../renderer/ConnectionListCellRenderer.java | 33 +- .../services/ConnectionService.java | 51 +++- .../services/ConnectionSettingsService.java | 102 +------ .../querytester/services/QueryService.java | 39 +-- .../querytester/ui/ConnectionSetupDialog.java | 22 +- .../intellij/querytester/ui/QueryTester.form | 285 ------------------ .../intellij/querytester/ui/QueryTester.java | 227 +++++++++++--- .../ui/components/AppSettingsComponent.java | 7 +- .../ui/components/ConnectionList.java | 39 ++- .../ui/components/ConnectionSelect.java | 82 ++--- .../components/ConnectionSetupComponent.form | 53 +++- .../components/ConnectionSetupComponent.java | 81 +++-- .../ui/components/DocumentAreaSelect.java | 30 +- .../ui/components/HistorySelect.java | 51 ++++ .../ui/components/MasterdataScopeSelect.java | 10 +- .../ui/components/NqlQueryTextbox.java | 11 +- .../ui/components/NscaleTable.java | 27 +- .../ui/components/ReconnectIcon.java | 39 +++ .../components/RepositoryRootTextField.java | 6 +- .../querytester/utils/ConnectionTestTask.java | 39 +++ 35 files changed, 1022 insertions(+), 642 deletions(-) create mode 100644 src/main/java/com/hsofttec/intellij/querytester/events/CheckServerConnectionEvent.java create mode 100644 src/main/java/com/hsofttec/intellij/querytester/events/CheckedServerConnectionEvent.java create mode 100644 src/main/java/com/hsofttec/intellij/querytester/models/ConnectionSettings.java create mode 100644 src/main/java/com/hsofttec/intellij/querytester/renderer/ComboBoxToolTipRenderer.java delete mode 100644 src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.form create mode 100644 src/main/java/com/hsofttec/intellij/querytester/ui/components/HistorySelect.java create mode 100644 src/main/java/com/hsofttec/intellij/querytester/ui/components/ReconnectIcon.java create mode 100644 src/main/java/com/hsofttec/intellij/querytester/utils/ConnectionTestTask.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 522cd64..e7e45b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ # Changelog ## [Unreleased] - ### Added ### Changed @@ -10,20 +9,22 @@ ### Security -## [1.0.1] - 2022-09-25 +## [1.0.1] - 2022-10-03 ### Added -- ui redesign - ### Changed +- ui redesign + ### Fixed ### Security ## [1.0.0] - 2022-09-20 + ### Added + - first release ### Changed diff --git a/src/main/java/com/hsofttec/intellij/querytester/QueryTesterConstants.java b/src/main/java/com/hsofttec/intellij/querytester/QueryTesterConstants.java index 6aef4a6..d62cf69 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/QueryTesterConstants.java +++ b/src/main/java/com/hsofttec/intellij/querytester/QueryTesterConstants.java @@ -28,5 +28,5 @@ public class QueryTesterConstants { public static final String DBEAN_NAME = "record"; public static final String DBEAN_PROPERTY_NAME_KEY = ""; public static final String DBEAN_PROPERTY_NAME_LINENO = ""; - public static final String DBEAN_PROPERTY_PRE_NAME_FOR_SQL_FUNC = "QueryFunction_"; + public static final String DBEAN_PROPERTY_PRE_NAME_FOR_NQL_FUNC = "NqlFunction_"; } diff --git a/src/main/java/com/hsofttec/intellij/querytester/QueryTesterToolWindowFactory.java b/src/main/java/com/hsofttec/intellij/querytester/QueryTesterToolWindowFactory.java index a491d2b..d292153 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/QueryTesterToolWindowFactory.java +++ b/src/main/java/com/hsofttec/intellij/querytester/QueryTesterToolWindowFactory.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester; import com.hsofttec.intellij.querytester.ui.QueryTester; @@ -16,7 +40,7 @@ public class QueryTesterToolWindowFactory implements ToolWindowFactory { * @param toolWindow current tool window */ public void createToolWindowContent( @NotNull Project project, @NotNull ToolWindow toolWindow ) { - Content content = ContentFactory.SERVICE.getInstance( ).createContent( new QueryTester( ), "", false ); + Content content = ContentFactory.SERVICE.getInstance( ).createContent( new QueryTester( project ), "", false ); toolWindow.getContentManager( ).addContent( content ); } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/CheckServerConnectionEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/CheckServerConnectionEvent.java new file mode 100644 index 0000000..b39006d --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/events/CheckServerConnectionEvent.java @@ -0,0 +1,28 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.events; + +public class CheckServerConnectionEvent { +} diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/CheckedServerConnectionEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/CheckedServerConnectionEvent.java new file mode 100644 index 0000000..d202bc7 --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/events/CheckedServerConnectionEvent.java @@ -0,0 +1,28 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.events; + +public class CheckedServerConnectionEvent { +} diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionAddedEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionAddedEvent.java index 0bbdd98..21487ee 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionAddedEvent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionAddedEvent.java @@ -1,15 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester.events; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; public class ConnectionAddedEvent { - private final ConnectionSettingsService.ConnectionSettings connectionSettings; + private final ConnectionSettings connectionSettings; - public ConnectionAddedEvent( ConnectionSettingsService.ConnectionSettings connectionSettings ) { + public ConnectionAddedEvent( ConnectionSettings connectionSettings ) { this.connectionSettings = connectionSettings; } - public ConnectionSettingsService.ConnectionSettings getData( ) { + public ConnectionSettings getData( ) { return connectionSettings; } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionChangedEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionChangedEvent.java index 4c40372..5eb876f 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionChangedEvent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionChangedEvent.java @@ -1,15 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester.events; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; public class ConnectionChangedEvent { - private final ConnectionSettingsService.ConnectionSettings connectionSettings; + private final ConnectionSettings connectionSettings; - public ConnectionChangedEvent( ConnectionSettingsService.ConnectionSettings connectionSettings ) { + public ConnectionChangedEvent( ConnectionSettings connectionSettings ) { this.connectionSettings = connectionSettings; } - public ConnectionSettingsService.ConnectionSettings getData( ) { + public ConnectionSettings getData( ) { return connectionSettings; } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionRemovedEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionRemovedEvent.java index 492a869..395f8bd 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionRemovedEvent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionRemovedEvent.java @@ -1,15 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester.events; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; public class ConnectionRemovedEvent { - private final ConnectionSettingsService.ConnectionSettings connectionSettings; + private final ConnectionSettings connectionSettings; - public ConnectionRemovedEvent( ConnectionSettingsService.ConnectionSettings connectionSettings ) { + public ConnectionRemovedEvent( ConnectionSettings connectionSettings ) { this.connectionSettings = connectionSettings; } - public ConnectionSettingsService.ConnectionSettings getData( ) { + public ConnectionSettings getData( ) { return connectionSettings; } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionSelectionChangedEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionSelectionChangedEvent.java index bc63410..925f774 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionSelectionChangedEvent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/events/ConnectionSelectionChangedEvent.java @@ -24,16 +24,16 @@ package com.hsofttec.intellij.querytester.events; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; public class ConnectionSelectionChangedEvent { - private final ConnectionSettingsService.ConnectionSettings connectionSettings; + private final ConnectionSettings connectionSettings; - public ConnectionSelectionChangedEvent( ConnectionSettingsService.ConnectionSettings connectionSettings ) { + public ConnectionSelectionChangedEvent( ConnectionSettings connectionSettings ) { this.connectionSettings = connectionSettings; } - public ConnectionSettingsService.ConnectionSettings getConnectionSettings( ) { + public ConnectionSettings getConnectionSettings( ) { return connectionSettings; } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/events/StartQueryExecutionEvent.java b/src/main/java/com/hsofttec/intellij/querytester/events/StartQueryExecutionEvent.java index bdeaa6f..b575b3a 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/events/StartQueryExecutionEvent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/events/StartQueryExecutionEvent.java @@ -25,12 +25,12 @@ package com.hsofttec.intellij.querytester.events; import com.hsofttec.intellij.querytester.QueryMode; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; public class StartQueryExecutionEvent { private final QueryExecutionParameters parameters; - public StartQueryExecutionEvent( ConnectionSettingsService.ConnectionSettings connectionSettings, + public StartQueryExecutionEvent( ConnectionSettings connectionSettings, QueryMode queryMode, String documentAreaName, String masterdataScope, @@ -45,7 +45,7 @@ public QueryExecutionParameters getData( ) { } public static class QueryExecutionParameters { - private final ConnectionSettingsService.ConnectionSettings connectionSettings; + private final ConnectionSettings connectionSettings; private final QueryMode queryMode; private final String documentAreaName; private final String masterdataScope; @@ -53,7 +53,7 @@ public static class QueryExecutionParameters { private final String nqlQuery; private final boolean aggregate; - public QueryExecutionParameters( ConnectionSettingsService.ConnectionSettings connectionSettings, + public QueryExecutionParameters( ConnectionSettings connectionSettings, QueryMode queryMode, String documentAreaName, String masterdataScope, @@ -69,7 +69,7 @@ public QueryExecutionParameters( ConnectionSettingsService.ConnectionSettings co this.aggregate = aggregate; } - public ConnectionSettingsService.ConnectionSettings getConnectionSettings( ) { + public ConnectionSettings getConnectionSettings( ) { return connectionSettings; } diff --git a/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionConfigurationComboBoxModel.java b/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionConfigurationComboBoxModel.java index b9fa43b..2c1a0ac 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionConfigurationComboBoxModel.java +++ b/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionConfigurationComboBoxModel.java @@ -24,25 +24,25 @@ package com.hsofttec.intellij.querytester.models; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; - import javax.swing.*; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Vector; -public class ConnectionConfigurationComboBoxModel extends DefaultComboBoxModel { - public ConnectionConfigurationComboBoxModel( ConnectionSettingsService.ConnectionSettings[] items ) { - super( items ); +public class ConnectionConfigurationComboBoxModel extends DefaultComboBoxModel { + public ConnectionConfigurationComboBoxModel( Collection items ) { + super( new Vector<>( items ) ); } @Override - public ConnectionSettingsService.ConnectionSettings getSelectedItem( ) { - return ( ConnectionSettingsService.ConnectionSettings ) super.getSelectedItem( ); + public ConnectionSettings getSelectedItem( ) { + return ( ConnectionSettings ) super.getSelectedItem( ); } - public List getItems( ) { + public List getItems( ) { int size = getSize( ); - List list = new ArrayList<>( size ); + List list = new ArrayList<>( size ); for ( int i = 0; i < size; i++ ) { list.add( getElementAt( i ) ); } diff --git a/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionSettings.java b/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionSettings.java new file mode 100644 index 0000000..0a8db43 --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/models/ConnectionSettings.java @@ -0,0 +1,136 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.models; + +import org.apache.commons.lang.RandomStringUtils; +import org.apache.commons.lang.StringUtils; + +public class ConnectionSettings { + private String id; + private boolean active; + private String connectionName; + private boolean ssl; + private String server; + private int port; + private int timeout; + private int connectTimeout; + private String instance; + private String username; + private String password; + + public ConnectionSettings( ) { + } + + public String getId( ) { + if ( StringUtils.isBlank( id ) ) { + id = RandomStringUtils.randomAlphanumeric( 20 ); + } + return id; + } + + public void setId( String id ) { + this.id = id; + } + + public String getConnectionName( ) { + return connectionName; + } + + public void setConnectionName( final String connectionName ) { + this.connectionName = connectionName; + } + + public boolean isSsl( ) { + return ssl; + } + + public void setSsl( final boolean ssl ) { + this.ssl = ssl; + } + + public String getServer( ) { + return server; + } + + public void setServer( final String server ) { + this.server = server; + } + + public int getPort( ) { + return port; + } + + public void setPort( final int port ) { + this.port = port; + } + + public String getInstance( ) { + return instance; + } + + public void setInstance( final String instance ) { + this.instance = instance; + } + + public String getUsername( ) { + return username; + } + + public void setUsername( final String username ) { + this.username = username; + } + + public String getPassword( ) { + return password; + } + + public void setPassword( final String password ) { + this.password = password; + } + + public int getTimeout( ) { + return timeout; + } + + public void setTimeout( int timeout ) { + this.timeout = timeout; + } + + public boolean isActive( ) { + return active; + } + + public void setActive( boolean active ) { + this.active = active; + } + + public int getConnectTimeout( ) { + return connectTimeout; + } + + public void setConnectTimeout( int connectTimeout ) { + this.connectTimeout = connectTimeout; + } +} diff --git a/src/main/java/com/hsofttec/intellij/querytester/models/FontFaceComboBoxModel.java b/src/main/java/com/hsofttec/intellij/querytester/models/FontFaceComboBoxModel.java index 4282a15..787fd81 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/models/FontFaceComboBoxModel.java +++ b/src/main/java/com/hsofttec/intellij/querytester/models/FontFaceComboBoxModel.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester.models; import javax.swing.*; @@ -6,6 +30,5 @@ public class FontFaceComboBoxModel extends DefaultComboBoxModel { public FontFaceComboBoxModel( ) { super( GraphicsEnvironment.getLocalGraphicsEnvironment( ).getAvailableFontFamilyNames( ) ); - } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/models/SettingsState.java b/src/main/java/com/hsofttec/intellij/querytester/models/SettingsState.java index 2363c4b..42937e3 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/models/SettingsState.java +++ b/src/main/java/com/hsofttec/intellij/querytester/models/SettingsState.java @@ -37,8 +37,6 @@ public class SettingsState { private int maxHistorySize; private String fontFace; private int fontSize; - private int lastMainDividerPosition; - private int lastLeftDividerPosition; public SettingsState( ) { showKeyColumn = true; @@ -48,7 +46,5 @@ public SettingsState( ) { maxResultSize = 100; fontFace = "JetBrains Mono"; fontSize = 14; - lastMainDividerPosition = 500; - lastLeftDividerPosition = 0; } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/renderer/ComboBoxToolTipRenderer.java b/src/main/java/com/hsofttec/intellij/querytester/renderer/ComboBoxToolTipRenderer.java new file mode 100644 index 0000000..d66eb91 --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/renderer/ComboBoxToolTipRenderer.java @@ -0,0 +1,40 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.renderer; + +import javax.swing.*; +import java.awt.*; + +public class ComboBoxToolTipRenderer extends DefaultListCellRenderer { + @Override + public Component getListCellRendererComponent( JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus ) { + JComponent comp = ( JComponent ) super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); + if ( -1 < index && null != value ) { + list.setToolTipText( ( String ) value ); + } + return comp; + } +} diff --git a/src/main/java/com/hsofttec/intellij/querytester/renderer/ConnectionListCellRenderer.java b/src/main/java/com/hsofttec/intellij/querytester/renderer/ConnectionListCellRenderer.java index fa135f6..6de7162 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/renderer/ConnectionListCellRenderer.java +++ b/src/main/java/com/hsofttec/intellij/querytester/renderer/ConnectionListCellRenderer.java @@ -1,6 +1,30 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester.renderer; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import javax.swing.*; import java.awt.*; @@ -12,11 +36,10 @@ public Component getListCellRendererComponent( JList list, int index, boolean isSelected, boolean cellHasFocus ) { - - if ( value instanceof ConnectionSettingsService.ConnectionSettings ) { - value = ( ( ConnectionSettingsService.ConnectionSettings ) value ).getConnectionName( ); + if ( value != null ) { + ConnectionSettings settings = ( ConnectionSettings ) value; + value = settings.getConnectionName( ); } - return super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus ); } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionService.java b/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionService.java index 251f6e3..10435e2 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionService.java +++ b/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionService.java @@ -36,7 +36,10 @@ import com.ceyoniq.nscale.al.core.repository.ResourceKey; import com.ceyoniq.nscale.al.core.repository.ResourceKeyInfo; import com.hsofttec.intellij.querytester.models.BaseResource; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; +import com.hsofttec.intellij.querytester.ui.Notifier; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,7 +74,7 @@ public static ConnectionService getInstance( ) { return instance; } - public void createConnection( ConnectionSettingsService.ConnectionSettings connectionSettings ) { + public void createConnection( ConnectionSettings connectionSettings ) { if ( !connectionSettings.getId( ).equals( connectionId ) ) { if ( session != null ) { @@ -92,6 +95,7 @@ public void createConnection( ConnectionSettingsService.ConnectionSettings conne advancedConnector.setInstanceName( connectionSettings.getInstance( ) ); advancedConnector.setSsl( connectionSettings.isSsl( ) ); advancedConnector.setTimeout( connectionSettings.getTimeout( ) ); + advancedConnector.setConnectTimeout( connectionSettings.getConnectTimeout( ) ); connectionId = connectionSettings.getId( ); String[] usernameParts = StringUtils.split( connectionSettings.getUsername( ), "@" ); @@ -295,4 +299,49 @@ public ResourceKey createDocument( BaseResource parentResource, ObjectclassName return resourceKey; } + + public boolean isConnectionUsable( ConnectionSettings settings ) { + boolean usable = false; + + if ( settings != null ) { + try { + createConnection( settings ); + usable = true; + } catch ( Exception e ) { + Notifier.warning( String.format( "connection '%s' not usable: %s", settings.getConnectionName( ), ExceptionUtils.getRootCauseMessage( e ) ) ); + } + } + + return usable; + } + + public Thread checkConnection( ConnectionSettings settings, Runnable successCallback ) { + return checkConnection( settings, successCallback, null, null ); + } + + public Thread checkConnection( ConnectionSettings settings, Runnable successCallback, Runnable finalCallback ) { + return checkConnection( settings, successCallback, null, finalCallback ); + } + + public Thread checkConnection( ConnectionSettings settings, Runnable successCallback, Runnable errorCallback, Runnable finalCallback ) { + Thread thread = new Thread( ( ) -> { + + boolean connectionUsable = isConnectionUsable( settings ); + if ( connectionUsable ) { + if ( successCallback != null ) { + successCallback.run( ); + } + } else { + if ( errorCallback != null ) { + errorCallback.run( ); + } + } + if ( finalCallback != null ) { + finalCallback.run( ); + } + } ); + thread.start( ); + return thread; + } + } diff --git a/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionSettingsService.java b/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionSettingsService.java index ddf82df..c2bac52 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionSettingsService.java +++ b/src/main/java/com/hsofttec/intellij/querytester/services/ConnectionSettingsService.java @@ -24,13 +24,12 @@ package com.hsofttec.intellij.querytester.services; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.util.xmlb.XmlSerializerUtil; -import org.apache.commons.lang.RandomStringUtils; -import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -89,103 +88,4 @@ public static class ConnectionSettingsState { public List connectionSettings = new ArrayList<>( ); } - public static class ConnectionSettings { - private String id; - private boolean active; - private String connectionName; - private boolean ssl; - private String server; - private int port; - private int timeout; - private String instance; - private String username; - private String password; - - public ConnectionSettings( ) { - } - - public String getId( ) { - if ( StringUtils.isBlank( id ) ) { - id = RandomStringUtils.randomAlphanumeric( 20 ); - } - return id; - } - - public void setId( String id ) { - this.id = id; - } - - public String getConnectionName( ) { - return connectionName; - } - - public void setConnectionName( final String connectionName ) { - this.connectionName = connectionName; - } - - public boolean isSsl( ) { - return ssl; - } - - public void setSsl( final boolean ssl ) { - this.ssl = ssl; - } - - public String getServer( ) { - return server; - } - - public void setServer( final String server ) { - this.server = server; - } - - public int getPort( ) { - return port; - } - - public void setPort( final int port ) { - this.port = port; - } - - public String getInstance( ) { - return instance; - } - - public void setInstance( final String instance ) { - this.instance = instance; - } - - public String getUsername( ) { - return username; - } - - public void setUsername( final String username ) { - this.username = username; - } - - public String getPassword( ) { - return password; - } - - public void setPassword( final String password ) { - this.password = password; - } - - public int getTimeout( ) { - return timeout; - } - - public void setTimeout( int timeout ) { - this.timeout = timeout; - } - - public boolean isActive( ) { - return active; - } - - public void setActive( boolean active ) { - this.active = active; - } - } - } diff --git a/src/main/java/com/hsofttec/intellij/querytester/services/QueryService.java b/src/main/java/com/hsofttec/intellij/querytester/services/QueryService.java index 82a117c..22a4243 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/services/QueryService.java +++ b/src/main/java/com/hsofttec/intellij/querytester/services/QueryService.java @@ -39,6 +39,7 @@ import com.ceyoniq.nscale.al.core.repository.ResourceResults; import com.hsofttec.intellij.querytester.QueryMode; import com.hsofttec.intellij.querytester.QueryTesterConstants; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.models.NscaleResult; import com.hsofttec.intellij.querytester.models.SettingsState; import com.hsofttec.intellij.querytester.ui.Notifier; @@ -55,7 +56,7 @@ public class QueryService { private static final ConnectionService connectionService = ConnectionService.getInstance( ); private static final SettingsState SETTINGS = SettingsService.getSettings( ); - public NscaleResult proccessQuery( ConnectionSettingsService.ConnectionSettings configuration, + public NscaleResult proccessQuery( ConnectionSettings configuration, QueryMode queryMode, String documentAreaName, String masterdataScope, @@ -161,45 +162,13 @@ private NscaleResult proccessRepositoryQuery( String documentAreaName, String re String propertyName = resultTable.getPropertyNames( )[ columnCounter ].getName( ); if ( propertyName.equals( "*" ) ) { propertyName = createFieldFunctionPropertyName( functionFieldPosition ); + functionFieldPosition++; } dynaBean.set( propertyName, resultTable.getCell( columnCounter, rowCounter ) ); } dynaBeans.add( dynaBean ); } -// for ( ResourceKey resourceKey : resultTable.getResourceKeys( ) ) { -// Map functionFieldPositions = new HashMap<>( ); -// int functionFieldPosition = 0; -// DynaBean dynaBean = dynaClass.newInstance( ); -// dynaBean.set( QueryTesterConstants.DBEAN_PROPERTY_NAME_KEY, resourceKey.getResourceId( ) ); -// dynaBean.set( QueryTesterConstants.DBEAN_PROPERTY_NAME_LINENO, ++counter ); -// int fieldPositionInRow = 0; -// -// for ( PropertyName propertyName : resultTable.getPropertyNames( ) ) { -// String name = propertyName.getName( ); -// if ( name.equals( "*" ) ) { -// functionFieldPositions.put( fieldPositionInRow, functionFieldPosition ); -// functionFieldPosition++; -// } else { -// if ( dynaBean.getDynaClass( ).getDynaProperty( name ) != null ) { -// Object value = resultTable.getCell( propertyName, resourceKey ); -// dynaBean.set( name, value ); -// } -// } -// fieldPositionInRow++; -// } -// -// if ( !functionFieldPositions.isEmpty( ) ) { -// for ( Map.Entry entry : functionFieldPositions.entrySet( ) ) { -// String fieldFunctionPropertyName = createFieldFunctionPropertyName( entry.getValue( ) ); -// Object value = resultTable.getCell( entry.getKey( ), counter - 1 ); -// dynaBean.set( fieldFunctionPropertyName, value ); -// } -// } -// -// dynaBeans.add( dynaBean ); -// } - return new NscaleResult( dynaClass, dynaBeans ); } @@ -247,6 +216,6 @@ private BasicDynaClass createDynaClass( PropertyName[] propertyNames ) { } public String createFieldFunctionPropertyName( int counter ) { - return String.format( "%s%d", QueryTesterConstants.DBEAN_PROPERTY_PRE_NAME_FOR_SQL_FUNC, counter ); + return String.format( "%s%d", QueryTesterConstants.DBEAN_PROPERTY_PRE_NAME_FOR_NQL_FUNC, counter ); } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/ConnectionSetupDialog.java b/src/main/java/com/hsofttec/intellij/querytester/ui/ConnectionSetupDialog.java index bc70feb..0ff268a 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/ConnectionSetupDialog.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/ConnectionSetupDialog.java @@ -24,14 +24,13 @@ package com.hsofttec.intellij.querytester.ui; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.services.ConnectionService; -import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; import com.hsofttec.intellij.querytester.ui.components.ConnectionSetupComponent; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.ValidationInfo; import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.exception.ExceptionUtils; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -65,7 +64,8 @@ protected ValidationInfo doValidate( ) { String server = connectionSetupComponent.getInputServer( ).getText( ); String port = connectionSetupComponent.getInputPort( ).getText( ); boolean ssl = connectionSetupComponent.getInputUseSSL( ).isSelected( ); - String timeout = connectionSetupComponent.getInputPort( ).getText( ); + String timeout = connectionSetupComponent.getInputTimeout( ).getText( ); + String connectTimeout = connectionSetupComponent.getInputConnectTimeout( ).getText( ); String username = connectionSetupComponent.getInputUsername( ).getText( ); String instance = connectionSetupComponent.getInputInstance( ).getText( ); char[] password = connectionSetupComponent.getInputPassword( ).getPassword( ); @@ -90,6 +90,10 @@ protected ValidationInfo doValidate( ) { return new ValidationInfo( "Timeout is mandatory and must be an integer value", connectionSetupComponent.getInputTimeout( ) ); } + if ( !StringUtils.isNumeric( connectTimeout ) ) { + return new ValidationInfo( "Connect-Timeout is mandatory and must be an integer value", connectionSetupComponent.getInputConnectTimeout( ) ); + } + if ( StringUtils.isBlank( instance ) ) { return new ValidationInfo( "Instance is mandatory and must be an integer value", connectionSetupComponent.getInputInstance( ) ); } @@ -103,30 +107,26 @@ protected ValidationInfo doValidate( ) { } if ( activated ) { - ConnectionSettingsService.ConnectionSettings settings = new ConnectionSettingsService.ConnectionSettings( ); + ConnectionSettings settings = new ConnectionSettings( ); settings.setConnectionName( connectioName ); settings.setServer( server ); settings.setPort( Integer.parseInt( port ) ); settings.setInstance( instance ); settings.setSsl( ssl ); settings.setTimeout( Integer.parseInt( timeout ) ); + settings.setConnectTimeout( Integer.parseInt( connectTimeout ) * 1000 ); settings.setUsername( username ); settings.setPassword( new String( password ) ); - try { - CONNECTION_SERVICE.createConnection( settings ); - } catch ( Exception e ) { - return new ValidationInfo( String.format( "connection '%s' not usable: %s", settings.getConnectionName( ), ExceptionUtils.getRootCauseMessage( e ) ) ); - } } return null; } - public ConnectionSettingsService.ConnectionSettings getData( ) { + public ConnectionSettings getData( ) { return connectionSetupComponent.getData( ); } - public void setData( ConnectionSettingsService.ConnectionSettings settings ) { + public void setData( ConnectionSettings settings ) { if ( StringUtils.isBlank( settings.getConnectionName( ) ) ) { setTitle( "Add New Connection Settings" ); diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.form b/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.form deleted file mode 100644 index e01f516..0000000 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.form +++ /dev/null @@ -1,285 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.java b/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.java index ba1b5eb..199d9b3 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/QueryTester.java @@ -28,18 +28,14 @@ import com.google.common.eventbus.Subscribe; import com.hsofttec.intellij.querytester.QueryMode; import com.hsofttec.intellij.querytester.QueryTesterConstants; -import com.hsofttec.intellij.querytester.events.ConnectionAddedEvent; -import com.hsofttec.intellij.querytester.events.PrepareQueryExecutionEvent; -import com.hsofttec.intellij.querytester.events.RootResourceIdChangedEvent; -import com.hsofttec.intellij.querytester.events.StartQueryExecutionEvent; +import com.hsofttec.intellij.querytester.events.*; import com.hsofttec.intellij.querytester.listeners.HistoryModifiedEventListener; import com.hsofttec.intellij.querytester.models.BaseResource; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.models.HistoryComboBoxModel; -import com.hsofttec.intellij.querytester.models.SettingsState; import com.hsofttec.intellij.querytester.services.ConnectionService; import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; import com.hsofttec.intellij.querytester.services.HistorySettingsService; -import com.hsofttec.intellij.querytester.services.SettingsService; import com.hsofttec.intellij.querytester.ui.components.*; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.*; @@ -47,20 +43,28 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.SimpleToolWindowPanel; +import com.intellij.ui.JBSplitter; +import com.intellij.ui.OnePixelSplitter; +import com.intellij.ui.components.*; +import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.UIUtil; +import com.jgoodies.forms.layout.CellConstraints; +import com.jgoodies.forms.layout.FormLayout; import org.apache.commons.beanutils.BasicDynaBean; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; public class QueryTester extends SimpleToolWindowPanel { private static final ConnectionSettingsService connectionSettingsService = ConnectionSettingsService.getSettings( ); - private static final ConnectionService connectionService = ConnectionService.getInstance( ); + private static final ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( ); private static final ProjectManager projectManager = ProjectManager.getInstance( ); - private static final HistorySettingsService HISTORY_SETTINGS_SERVICE = HistorySettingsService.getSettings( ProjectManager.getInstance( ).getOpenProjects( )[ 0 ] ); + private static final HistorySettingsService HISTORY_SETTINGS_SERVICE = HistorySettingsService.getSettings( projectManager.getOpenProjects( )[ 0 ] ); private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); - private static final SettingsState settings = SettingsService.getSettings( ); + private final Project project; private JPanel mainPanel; private ConnectionSelect inputSelectedConnection; @@ -68,44 +72,22 @@ public class QueryTester extends SimpleToolWindowPanel { private NqlQueryTextbox inputNqlQuery; private JComboBox inputHistory; private RepositoryRootTextField inputRepositoryRoot; - private JLabel labelDocumentArea; private DocumentAreaSelect inputDocumentArea; - private JTabbedPane tabbedPane; - private JPanel tabRepository; - private JPanel tabMasterdata; - private JPanel tabBPMN; - private JPanel tabPrinicipals; - private JPanel tabWorkflow; + private JBTabbedPane tabbedPane; private JCheckBox inputeAggregate; - private JComboBox inputMasterdataScope; - private JSplitPane mainSplitter; - private JSplitPane leftSplitPane; - private JPanel rightPanel; - private JPanel leftPanel; + private MasterdataScopeSelect inputMasterdataScope; + private ReconnectIcon iconReconnect; - public QueryTester( ) { + public QueryTester( Project project ) { super( false, true ); + this.project = project; EVENT_BUS.register( this ); setToolbar( createToolBar( ) ); - setContent( mainPanel ); - mainSplitter.setOneTouchExpandable( false ); - leftSplitPane.setOneTouchExpandable( false ); - mainSplitter.setDividerLocation( settings.getLastMainDividerPosition( ) ); - if ( settings.getLastLeftDividerPosition( ) > 0 ) { - leftSplitPane.setDividerLocation( settings.getLastLeftDividerPosition( ) ); - } -// mainSplitter.setContinuousLayout( true ); -// mainSplitter.setResizeWeight( .5 ); -// mainSplitter.setDividerSize( 3 ); -// mainSplitter.setBorder( BorderFactory.createEmptyBorder( ) ); - mainSplitter.addPropertyChangeListener( JSplitPane.DIVIDER_LOCATION_PROPERTY, propertyChangeEvent -> { - settings.setLastMainDividerPosition( ( Integer ) propertyChangeEvent.getNewValue( ) ); - } ); - leftSplitPane.addPropertyChangeListener( JSplitPane.DIVIDER_LOCATION_PROPERTY, propertyChangeEvent -> { - settings.setLastLeftDividerPosition( ( Integer ) propertyChangeEvent.getNewValue( ) ); - } ); + setContent( createUIComponents( ) ); + + inputSelectedConnection.reloadItems( ); ResultTableContextMenu resultTableContextMenu = new ResultTableContextMenu( ); queryResultTable.setComponentPopupMenu( resultTableContextMenu ); @@ -125,7 +107,7 @@ public void actionPerformed( ActionEvent actionEvent ) { public void actionPerformed( ActionEvent actionEvent ) { BasicDynaBean basicDynaBean = ( BasicDynaBean ) queryResultTable.getValueAt( queryResultTable.getSelectedRow( ), queryResultTable.getSelectedColumn( ) ); String resourceId = ( String ) basicDynaBean.get( QueryTesterConstants.DBEAN_PROPERTY_NAME_KEY ); - BaseResource baseResource = connectionService.getBaseResource( resourceId ); + BaseResource baseResource = CONNECTION_SERVICE.getBaseResource( resourceId ); inputRepositoryRoot.setText( baseResource.getParentresourceid( ) ); EVENT_BUS.post( new PrepareQueryExecutionEvent( ) ); } @@ -159,7 +141,55 @@ public void notifyRemove( String query ) { * @param event empty event */ @Subscribe - public void prepareQueryExecution( PrepareQueryExecutionEvent event ) { + public void checkServerConnectionEventHandler( CheckServerConnectionEvent event ) { + UIUtil.invokeLaterIfNeeded( ( ) -> { + inputSelectedConnection.setEnabled( false ); + queryResultTable.setEnabled( false ); + inputNqlQuery.setEnabled( false ); + inputHistory.setEnabled( false ); + inputDocumentArea.setEnabled( false ); + iconReconnect.setEnabled( false ); + inputeAggregate.setEnabled( false ); + inputMasterdataScope.setEnabled( false ); + inputRepositoryRoot.setEnabled( false ); + } ); + } + + @Subscribe + public void checkedServerConnectionEventHandler( CheckedServerConnectionEvent event ) { + UIUtil.invokeLaterIfNeeded( ( ) -> { + inputSelectedConnection.setEnabled( true ); + queryResultTable.setEnabled( true ); + inputNqlQuery.setEnabled( true ); + inputHistory.setEnabled( true ); + inputDocumentArea.setEnabled( true ); + iconReconnect.setEnabled( true ); + inputeAggregate.setEnabled( true ); + inputMasterdataScope.setEnabled( true ); + inputRepositoryRoot.setEnabled( true ); + } ); + } + + @Subscribe + public void connectionSelectionChangedEventHandler( ConnectionSelectionChangedEvent event ) { + + if ( event.getConnectionSettings( ) != null ) { + UIUtil.invokeLaterIfNeeded( ( ) -> { + inputSelectedConnection.setEnabled( true ); + queryResultTable.setEnabled( true ); + inputNqlQuery.setEnabled( true ); + inputHistory.setEnabled( true ); + inputDocumentArea.setEnabled( true ); + iconReconnect.setEnabled( true ); + inputeAggregate.setEnabled( true ); + inputMasterdataScope.setEnabled( true ); + inputRepositoryRoot.setEnabled( true ); + } ); + } + } + + @Subscribe + public void prepareQueryExecutionEventHandler( PrepareQueryExecutionEvent event ) { QueryMode queryMode = QueryMode.REPOSITORY; if ( inputDocumentArea.getSelectedIndex( ) == -1 || inputSelectedConnection.getSelectedIndex( ) == -1 ) { @@ -167,7 +197,7 @@ public void prepareQueryExecution( PrepareQueryExecutionEvent event ) { return; } - ConnectionSettingsService.ConnectionSettings connectionSettings = ( ConnectionSettingsService.ConnectionSettings ) inputSelectedConnection.getSelectedItem( ); + ConnectionSettings connectionSettings = ( ConnectionSettings ) inputSelectedConnection.getSelectedItem( ); String documentAreaName = ( String ) inputDocumentArea.getSelectedItem( ); String masterdataScope = ( String ) inputMasterdataScope.getSelectedItem( ); String repositoryRoot = inputRepositoryRoot.getText( ); @@ -201,7 +231,7 @@ public void prepareQueryExecution( PrepareQueryExecutionEvent event ) { } @Subscribe - public void rootResourceIdChanged( RootResourceIdChangedEvent event ) { + public void rootResourceIdChangedEventHandler( RootResourceIdChangedEvent event ) { inputRepositoryRoot.setText( event.getRootResourceId( ) ); EVENT_BUS.post( new PrepareQueryExecutionEvent( ) ); } @@ -220,7 +250,7 @@ public void actionPerformed( @NotNull AnActionEvent e ) { @Override public void actionPerformed( AnActionEvent actionEvent ) { Project currentProject = actionEvent.getProject( ); - ConnectionSettingsService.ConnectionSettings connectionSettings = new ConnectionSettingsService.ConnectionSettings( ); + ConnectionSettings connectionSettings = new ConnectionSettings( ); ConnectionSetupDialog connectionSetupDialog = new ConnectionSetupDialog( currentProject ); connectionSetupDialog.setData( connectionSettings ); if ( connectionSetupDialog.showAndGet( ) ) { @@ -234,7 +264,7 @@ public void actionPerformed( AnActionEvent actionEvent ) { actionGroup.add( new AnAction( "Plugin Settings", "Plugin Settings for nscale QueryTester", AllIcons.General.Settings ) { @Override public void actionPerformed( @NotNull AnActionEvent e ) { - ShowSettingsUtil.getInstance( ).showSettingsDialog( projectManager.getOpenProjects( )[ 0 ], "nscale QueryTester Settings" ); + ShowSettingsUtil.getInstance( ).showSettingsDialog( projectManager.getOpenProjects( )[ 0 ], "QueryTester" ); } } ); @@ -244,10 +274,107 @@ public void actionPerformed( @NotNull AnActionEvent e ) { return actionToolbar.getComponent( ); } - private void createUIComponents( ) { - inputNqlQuery = new NqlQueryTextbox( ); - inputMasterdataScope = new MasterdataScopeSelect( ); - inputDocumentArea = new DocumentAreaSelect( ); - inputSelectedConnection = new ConnectionSelect( ); + private JComponent createUIComponents( ) { + mainPanel = new JPanel( new BorderLayout( -1, -1 ) ); + + JBSplitter mainSplitter = new OnePixelSplitter( false, 0.8f ); + mainSplitter.setHonorComponentsMinimumSize( true ); + mainSplitter.setSplitterProportionKey( "main.splitter.key" ); + + JBSplitter leftPaneSplitter = new OnePixelSplitter( true, 03f ); + leftPaneSplitter.setHonorComponentsMinimumSize( true ); + leftPaneSplitter.setSplitterProportionKey( "query.splitter.key" ); + + JBPanel leftPanel = new JBPanel<>( new BorderLayout( 3, 3 ) ); + JBPanel rightPanel = new JBPanel<>( new BorderLayout( 3, 3 ) ); + rightPanel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); + leftPanel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); + leftPanel.add( leftPaneSplitter ); + + mainSplitter.setFirstComponent( leftPanel ); + mainSplitter.setSecondComponent( rightPanel ); + + inputNqlQuery = new NqlQueryTextbox( project ); + queryResultTable = new NscaleTable( project ); + + JPanel firstPanel = JBUI.Panels.simplePanel( ); + firstPanel.add( new JBScrollPane( inputNqlQuery ) ); + firstPanel.setBorder( BorderFactory.createEtchedBorder( ) ); + + JPanel secondPanel = JBUI.Panels.simplePanel( ); + secondPanel.add( new JBScrollPane( queryResultTable ) ); + secondPanel.setBorder( BorderFactory.createEtchedBorder( ) ); + + leftPaneSplitter.setFirstComponent( firstPanel ); + leftPaneSplitter.setSecondComponent( secondPanel ); + + mainPanel.add( mainSplitter ); + + rightPanel.add( createFormPanel( rightPanel ), BorderLayout.NORTH ); + rightPanel.add( createTabPanel( ), BorderLayout.CENTER, 1 ); + + return mainPanel; + } + + private JComponent createTabPanel( ) { + CellConstraints cc = new CellConstraints( ); + FormLayout formLayout = new FormLayout( + "5px, left:pref, 4dlu, pref:grow", + "pref, 3dlu, pref, 3dlu, pref" + ); + JPanel repositoryPanel = new JPanel( formLayout ); + JPanel masterdataPanel = new JPanel( formLayout ); + + inputRepositoryRoot = new RepositoryRootTextField( project ); + repositoryPanel.add( new JBLabel( "Root resource" ), cc.xy( 2, 1 ) ); + repositoryPanel.add( inputRepositoryRoot, cc.xy( 4, 1 ) ); + + inputeAggregate = new JBCheckBox( "Aggregate" ); + repositoryPanel.add( inputeAggregate, cc.xy( 4, 3 ) ); + + inputMasterdataScope = new MasterdataScopeSelect( project ); + masterdataPanel.add( new JBLabel( "Scope" ), cc.xy( 2, 1 ) ); + masterdataPanel.add( inputMasterdataScope, cc.xy( 4, 1 ) ); + + tabbedPane = new JBTabbedPane( ); + tabbedPane.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); + tabbedPane.addTab( "Repository", repositoryPanel ); + tabbedPane.addTab( "Masterdata", masterdataPanel ); + tabbedPane.setBorder( BorderFactory.createEtchedBorder( ) ); + return tabbedPane; + } + + private JComponent createFormPanel( JPanel panel ) { + int formRow; + int[] formColNums = { 2, 4, 6 }; + CellConstraints cc = new CellConstraints( ); + FormLayout formLayout = new FormLayout( + "5px, left:pref, 4dlu, pref:grow, 4dlu, pref,5px", + "pref, 3dlu, pref, 3dlu, pref" + ); + JPanel formPanel = new JPanel( formLayout ); + panel.add( formPanel, BorderLayout.NORTH ); + formPanel.setBorder( BorderFactory.createEtchedBorder( ) ); + + formRow = 1; + inputSelectedConnection = new ConnectionSelect( project ); + iconReconnect = new ReconnectIcon( inputSelectedConnection ); + + formPanel.add( new JBLabel( "Connection" ), cc.xy( formColNums[ 0 ], formRow ) ); + formPanel.add( inputSelectedConnection, cc.xy( formColNums[ 1 ], formRow ) ); + formPanel.add( iconReconnect, cc.xy( formColNums[ 2 ], formRow ) ); + + formRow += 2; + inputDocumentArea = new DocumentAreaSelect( project ); + formPanel.add( new JBLabel( "Document area" ), cc.xy( formColNums[ 0 ], formRow ) ); + formPanel.add( inputDocumentArea, cc.xyw( formColNums[ 1 ], formRow, 3 ) ); + + formRow += 2; + inputHistory = new HistorySelect( project ); + inputHistory.setPrototypeDisplayValue( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ); + formPanel.add( new JBLabel( "History" ), cc.xy( formColNums[ 0 ], formRow ) ); + formPanel.add( inputHistory, cc.xyw( formColNums[ 1 ], formRow, 3 ) ); + + return formPanel; } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/AppSettingsComponent.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/AppSettingsComponent.java index f6ddf35..2c34066 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/AppSettingsComponent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/AppSettingsComponent.java @@ -28,6 +28,7 @@ import com.hsofttec.intellij.querytester.events.ConnectionAddedEvent; import com.hsofttec.intellij.querytester.events.ConnectionChangedEvent; import com.hsofttec.intellij.querytester.events.ConnectionRemovedEvent; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.models.FontFaceComboBoxModel; import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; import com.hsofttec.intellij.querytester.ui.ConnectionSetupDialog; @@ -147,7 +148,7 @@ private void createConnectionsToolbar( ) { ToolbarDecorator decorationToolbar = ToolbarDecorator.createDecorator( listConnections ); decorationToolbar.setAddAction( anActionButton -> { Project currentProject = projectManager.getOpenProjects( )[ 0 ]; - ConnectionSettingsService.ConnectionSettings connectionSettings = new ConnectionSettingsService.ConnectionSettings( ); + ConnectionSettings connectionSettings = new ConnectionSettings( ); ConnectionSetupDialog connectionSetupDialog = new ConnectionSetupDialog( currentProject ); connectionSetupDialog.setData( connectionSettings ); if ( connectionSetupDialog.showAndGet( ) ) { @@ -158,13 +159,13 @@ private void createConnectionsToolbar( ) { } } ); decorationToolbar.setRemoveAction( anActionButton -> { - ConnectionSettingsService.ConnectionSettings selectedValue = listConnections.getSelectedValue( ); + ConnectionSettings selectedValue = listConnections.getSelectedValue( ); listConnections.removeElement( selectedValue ); connectionSettingsService.removeConnection( selectedValue.getId( ) ); EVENT_BUS.post( new ConnectionRemovedEvent( selectedValue ) ); } ); decorationToolbar.setEditAction( anActionButton -> { - ConnectionSettingsService.ConnectionSettings selectedValue = listConnections.getSelectedValue( ); + ConnectionSettings selectedValue = listConnections.getSelectedValue( ); Project currentProject = projectManager.getOpenProjects( )[ 0 ]; ConnectionSetupDialog connectionSetupDialog = new ConnectionSetupDialog( currentProject ); connectionSetupDialog.setData( selectedValue ); diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionList.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionList.java index f892a15..286837f 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionList.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionList.java @@ -1,6 +1,31 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package com.hsofttec.intellij.querytester.ui.components; import com.google.common.eventbus.EventBus; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.renderer.ConnectionListCellRenderer; import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; import com.hsofttec.intellij.querytester.ui.EventBusFactory; @@ -8,7 +33,7 @@ import javax.swing.*; -public class ConnectionList extends JBList { +public class ConnectionList extends JBList { private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); private static final ConnectionSettingsService connectionSettingsService = ConnectionSettingsService.getSettings( ); @@ -18,18 +43,18 @@ public ConnectionList( ) { setCellRenderer( new ConnectionListCellRenderer( ) ); } - public ConnectionSettingsService.ConnectionSettings getSelectedItem( ) { - ListModel model = getModel( ); + public ConnectionSettings getSelectedItem( ) { + ListModel model = getModel( ); return model.getElementAt( getSelectedIndex( ) ); } - public void addElement( ConnectionSettingsService.ConnectionSettings connectionSettings ) { - DefaultListModel model = ( DefaultListModel ) getModel( ); + public void addElement( ConnectionSettings connectionSettings ) { + DefaultListModel model = ( DefaultListModel ) getModel( ); model.addElement( connectionSettings ); } - public void removeElement( ConnectionSettingsService.ConnectionSettings connectionSettings ) { - DefaultListModel model = ( DefaultListModel ) getModel( ); + public void removeElement( ConnectionSettings connectionSettings ) { + DefaultListModel model = ( DefaultListModel ) getModel( ); model.removeElement( connectionSettings ); } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSelect.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSelect.java index 039c130..67621e9 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSelect.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSelect.java @@ -26,76 +26,79 @@ import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; -import com.hsofttec.intellij.querytester.events.ConnectionAddedEvent; -import com.hsofttec.intellij.querytester.events.ConnectionChangedEvent; -import com.hsofttec.intellij.querytester.events.ConnectionRemovedEvent; -import com.hsofttec.intellij.querytester.events.ConnectionSelectionChangedEvent; -import com.hsofttec.intellij.querytester.models.ConnectionConfigurationComboBoxModel; +import com.hsofttec.intellij.querytester.events.*; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.renderer.ConnectionListCellRenderer; import com.hsofttec.intellij.querytester.services.ConnectionService; import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; import com.hsofttec.intellij.querytester.ui.EventBusFactory; -import com.hsofttec.intellij.querytester.ui.Notifier; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; -import org.apache.commons.lang.exception.ExceptionUtils; +import com.intellij.ui.CollectionComboBoxModel; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.List; +import java.util.stream.Collectors; -public class ConnectionSelect extends ComboBox implements ItemListener { +public class ConnectionSelect extends ComboBox implements ItemListener { private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); - private static final ConnectionSettingsService connectionSettingsService = ConnectionSettingsService.getSettings( ); - + private static final ConnectionSettingsService CONNECTION_SETTINGS_SERVICE = ConnectionSettingsService.getSettings( ); private static final ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( ); + private final Project project; - public ConnectionSelect( ) { + public ConnectionSelect( Project project ) { EVENT_BUS.register( this ); + this.project = project; this.addItemListener( this ); setRenderer( new ConnectionListCellRenderer( ) ); - setModel( new ConnectionConfigurationComboBoxModel( connectionSettingsService.connectionSettingsState.connectionSettings.stream( ) - .filter( ConnectionSettingsService.ConnectionSettings::isActive ).toArray( ConnectionSettingsService.ConnectionSettings[]::new ) ) ); - ConnectionSettingsService.ConnectionSettings settings = ( ConnectionSettingsService.ConnectionSettings ) getSelectedItem( ); + } + + public void reloadItems( ) { + List connectionSettings = CONNECTION_SETTINGS_SERVICE.connectionSettingsState.connectionSettings.stream( ) + .filter( ConnectionSettings::isActive ).collect( Collectors.toList( ) ); + + setModel( new CollectionComboBoxModel<>( connectionSettings ) ); - if ( isConnectionUsable( settings ) ) { - EVENT_BUS.post( new ConnectionSelectionChangedEvent( settings ) ); - } else { - EVENT_BUS.post( new ConnectionSelectionChangedEvent( null ) ); + ConnectionSettings settings = ( ConnectionSettings ) getSelectedItem( ); + if ( settings != null ) { + checkOnlineState( settings ); } } @Override public void itemStateChanged( ItemEvent itemEvent ) { if ( itemEvent.getStateChange( ) == ItemEvent.SELECTED ) { - ConnectionSettingsService.ConnectionSettings settings = ( ConnectionSettingsService.ConnectionSettings ) getSelectedItem( ); - if ( isConnectionUsable( settings ) ) { - EVENT_BUS.post( new ConnectionSelectionChangedEvent( settings ) ); - } else { - EVENT_BUS.post( new ConnectionSelectionChangedEvent( null ) ); + ConnectionSettings settings = ( ConnectionSettings ) getSelectedItem( ); + if ( settings != null ) { + checkOnlineState( settings ); } } } - private boolean isConnectionUsable( ConnectionSettingsService.ConnectionSettings settings ) { - boolean usable = false; - - if ( settings != null ) { - try { - CONNECTION_SERVICE.createConnection( settings ); - usable = true; - } catch ( Exception e ) { - Notifier.warning( String.format( "connection '%s' not usable: %s", settings.getConnectionName( ), ExceptionUtils.getRootCauseMessage( e ) ) ); + public void checkOnlineState( ConnectionSettings settings ) { + EVENT_BUS.post( new CheckServerConnectionEvent( ) ); + ProgressManager progressManager = ProgressManager.getInstance( ); + progressManager.runProcessWithProgressSynchronously( ( ) -> { + final ProgressIndicator progressIndicator = progressManager.getProgressIndicator( ); + progressIndicator.setText( String.format( "Testing server '%s'", settings.getConnectionName( ) ) ); + if ( CONNECTION_SERVICE.isConnectionUsable( settings ) ) { + EVENT_BUS.post( new ConnectionSelectionChangedEvent( settings ) ); + } else { + EVENT_BUS.post( new ConnectionSelectionChangedEvent( null ) ); } - } - - return usable; + EVENT_BUS.post( new CheckedServerConnectionEvent( ) ); + }, "Testing connection", false, project, this ); } @Subscribe public void connectionSettingsChanged( ConnectionChangedEvent event ) { boolean foundInSelectBox = false; - ConnectionSettingsService.ConnectionSettings changedSettings = event.getData( ); - ConnectionConfigurationComboBoxModel model = ( ConnectionConfigurationComboBoxModel ) getModel( ); - for ( ConnectionSettingsService.ConnectionSettings item : model.getItems( ) ) { + ConnectionSettings changedSettings = event.getData( ); + CollectionComboBoxModel model = ( CollectionComboBoxModel ) getModel( ); + for ( ConnectionSettings item : model.getItems( ) ) { if ( item.getId( ).equals( changedSettings.getId( ) ) ) { foundInSelectBox = true; if ( !changedSettings.isActive( ) ) { @@ -125,7 +128,7 @@ public void connectionSettingsAdded( ConnectionAddedEvent event ) { addItem( event.getData( ) ); if ( getItemCount( ) == 1 ) { setSelectedIndex( 0 ); - EVENT_BUS.post( new ConnectionSelectionChangedEvent( ( ConnectionSettingsService.ConnectionSettings ) getSelectedItem( ) ) ); + EVENT_BUS.post( new ConnectionSelectionChangedEvent( ( ConnectionSettings ) getSelectedItem( ) ) ); } } @@ -133,4 +136,5 @@ public void connectionSettingsAdded( ConnectionAddedEvent event ) { public void connectionSettingsRemoved( ConnectionRemovedEvent event ) { removeItem( event.getData( ) ); } + } diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.form b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.form index 87c1f68..c0ef11c 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.form +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.form @@ -1,16 +1,16 @@
- + - + - + @@ -18,9 +18,9 @@ - + - + @@ -57,7 +57,7 @@ - + @@ -65,7 +65,7 @@ - + @@ -73,7 +73,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -97,7 +97,7 @@ - + @@ -115,15 +115,15 @@ - + - + - + @@ -131,7 +131,7 @@ - + @@ -145,6 +145,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.java index 0981f02..327d35a 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ConnectionSetupComponent.java @@ -24,15 +24,26 @@ package com.hsofttec.intellij.querytester.ui.components; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; +import com.hsofttec.intellij.querytester.services.ConnectionService; import com.hsofttec.intellij.querytester.services.ConnectionSettingsService; +import com.hsofttec.intellij.querytester.ui.Notifier; +import com.intellij.ide.plugins.newui.LinkComponent; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.ui.AnimatedIcon; +import lombok.SneakyThrows; import javax.swing.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; public class ConnectionSetupComponent { - private ConnectionSettingsService.ConnectionSettings settings; - private JTextField inputConnectioName; + private final static ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( ); + + private ConnectionSettings settings; + private JTextField inputConnectionName; private JPanel mainPanel; - private JLabel labelConnectioName; + private JLabel labelConnectionName; private JLabel labelServer; private JLabel labelPort; private JCheckBox inputUseSSL; @@ -45,12 +56,37 @@ public class ConnectionSetupComponent { private JPasswordField inputPassword; private JLabel labelPassword; private JTextField inputTimeout; + private JTextField inputConnectTimeout; private JLabel labelTimeout; private JCheckBox inputConnectionActivated; + private JLabel labelConnectTimeout; + private LinkComponent linkTestConnection; private JTextField inputSourceFolder; private JTextArea inputScriptTemplate; public ConnectionSetupComponent( ) { + linkTestConnection.addMouseListener( new MouseAdapter( ) { + @Override + public void mouseClicked( MouseEvent mouseEvent ) { + linkTestConnection.setIcon( new AnimatedIcon.Default( ) ); + linkTestConnection.setEnabled( false ); + + ApplicationManager.getApplication( ).invokeLaterOnWriteThread( new Runnable( ) { + @SneakyThrows + @Override + public void run( ) { + ConnectionSettings data = getData( ); + CONNECTION_SERVICE.checkConnection( data, + ( ) -> Notifier.information( "Connection tested successfully" ), + ( ) -> Notifier.warning( "Connection not successfully" ), + ( ) -> { + linkTestConnection.setEnabled( true ); + linkTestConnection.setIcon( null ); + } ); + } + } ); + } + } ); } public JPanel getMainPanel( ) { @@ -58,13 +94,17 @@ public JPanel getMainPanel( ) { } public JTextField getInputConnectioName( ) { - return inputConnectioName; + return inputConnectionName; } public JTextField getInputTimeout( ) { return inputTimeout; } + public JTextField getInputConnectTimeout( ) { + return inputConnectTimeout; + } + public JCheckBox getInputUseSSL( ) { return inputUseSSL; } @@ -93,36 +133,39 @@ public JCheckBox getInputConnectionActivated( ) { return inputConnectionActivated; } - public void setData( ConnectionSettingsService.ConnectionSettings data ) { + public void setData( ConnectionSettings data ) { settings = data; - if ( settings != null ) { - inputConnectionActivated.setSelected( settings.isActive( ) ); - inputConnectioName.setText( settings.getConnectionName( ) ); - inputUseSSL.setSelected( settings.isSsl( ) ); - inputServer.setText( settings.getServer( ) ); - inputPort.setText( String.valueOf( settings.getPort( ) ) ); - inputTimeout.setText( String.valueOf( settings.getTimeout( ) ) ); - inputInstance.setText( settings.getInstance( ) ); - inputUsername.setText( settings.getUsername( ) ); - inputPassword.setText( settings.getPassword( ) ); - } else { + if ( settings == null ) { settings.setActive( true ); settings.setServer( "127.0.0.1" ); settings.setPort( 8080 ); settings.setSsl( false ); settings.setInstance( "nscalealinst1" ); settings.setUsername( "admin@nscale" ); - settings.setTimeout( 0 ); + settings.setTimeout( 10 ); + settings.setConnectTimeout( 10000 ); } + + inputConnectionActivated.setSelected( settings.isActive( ) ); + inputConnectionName.setText( settings.getConnectionName( ) ); + inputUseSSL.setSelected( settings.isSsl( ) ); + inputServer.setText( settings.getServer( ) ); + inputPort.setText( String.valueOf( settings.getPort( ) ) ); + inputTimeout.setText( String.valueOf( settings.getTimeout( ) ) ); + inputConnectTimeout.setText( String.valueOf( settings.getConnectTimeout( ) / 1000 ) ); + inputInstance.setText( settings.getInstance( ) ); + inputUsername.setText( settings.getUsername( ) ); + inputPassword.setText( settings.getPassword( ) ); } - public ConnectionSettingsService.ConnectionSettings getData( ) { + public ConnectionSettings getData( ) { settings.setActive( inputConnectionActivated.isSelected( ) ); - settings.setConnectionName( inputConnectioName.getText( ) ); + settings.setConnectionName( inputConnectionName.getText( ) ); settings.setSsl( inputUseSSL.isSelected( ) ); settings.setServer( inputServer.getText( ) ); settings.setPort( Integer.parseInt( inputPort.getText( ) ) ); settings.setTimeout( Integer.parseInt( inputTimeout.getText( ) ) ); + settings.setConnectTimeout( Integer.parseInt( inputConnectTimeout.getText( ) ) * 1000 ); settings.setInstance( inputInstance.getText( ) ); settings.setUsername( inputUsername.getText( ) ); settings.setPassword( inputPassword.getText( ) ); diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/DocumentAreaSelect.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/DocumentAreaSelect.java index f839e74..bd68b7f 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/DocumentAreaSelect.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/DocumentAreaSelect.java @@ -30,8 +30,10 @@ import com.google.common.eventbus.Subscribe; import com.hsofttec.intellij.querytester.events.ConnectionSelectionChangedEvent; import com.hsofttec.intellij.querytester.events.DocumentAreaChangedEvent; +import com.hsofttec.intellij.querytester.models.ConnectionSettings; import com.hsofttec.intellij.querytester.services.ConnectionService; import com.hsofttec.intellij.querytester.ui.EventBusFactory; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.ui.CollectionComboBoxModel; @@ -43,10 +45,13 @@ public class DocumentAreaSelect extends ComboBox implements ItemListener { private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); - private static final ConnectionService connectionService = ConnectionService.getInstance( ); - private List docAreaNames = new ArrayList<>( ); + private static final ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( ); - public DocumentAreaSelect( ) { + private final Project project; + private final List docAreaNames = new ArrayList<>( ); + + public DocumentAreaSelect( Project project ) { + this.project = project; EVENT_BUS.register( this ); setModel( new CollectionComboBoxModel<>( docAreaNames ) ); addItemListener( this ); @@ -59,15 +64,20 @@ public void setSelectedIndex( int index ) { } @Subscribe - public void connectionSelectionChanged( ConnectionSelectionChangedEvent event ) { - Session session = connectionService.getSession( ); + public void connectionSelectionChangedEventHandler( ConnectionSelectionChangedEvent event ) { + final ConnectionSettings selectedItem = event.getConnectionSettings( ); + docAreaNames.clear( ); setSelectedIndex( -1 ); - if ( session != null ) { - List documentAreas = connectionService.getSession( ).getConfigurationService( ).getDocumentAreas( ); - docAreaNames.addAll( documentAreas.stream( ).map( DocumentArea::getAreaName ).collect( Collectors.toList( ) ) ); - if ( !documentAreas.isEmpty( ) ) { - setSelectedIndex( 0 ); + + if ( selectedItem != null ) { + Session session = CONNECTION_SERVICE.getSession( ); + if ( session != null ) { + List documentAreas = CONNECTION_SERVICE.getSession( ).getConfigurationService( ).getDocumentAreas( ); + docAreaNames.addAll( documentAreas.stream( ).map( DocumentArea::getAreaName ).collect( Collectors.toList( ) ) ); + if ( !documentAreas.isEmpty( ) ) { + setSelectedIndex( 0 ); + } } } } diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/HistorySelect.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/HistorySelect.java new file mode 100644 index 0000000..9dbdae4 --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/HistorySelect.java @@ -0,0 +1,51 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.ui.components; + +import com.google.common.eventbus.EventBus; +import com.hsofttec.intellij.querytester.renderer.ComboBoxToolTipRenderer; +import com.hsofttec.intellij.querytester.ui.EventBusFactory; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.ComboBox; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +public class HistorySelect extends ComboBox implements ItemListener { + private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); + + private final Project project; + + public HistorySelect( Project project ) { + EVENT_BUS.register( this ); + this.project = project; + setRenderer( new ComboBoxToolTipRenderer( ) ); + } + + @Override + public void itemStateChanged( ItemEvent e ) { + + } +} diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/MasterdataScopeSelect.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/MasterdataScopeSelect.java index e006bae..c1bfe97 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/MasterdataScopeSelect.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/MasterdataScopeSelect.java @@ -32,6 +32,7 @@ import com.hsofttec.intellij.querytester.events.MasterdataScopeChangedEvent; import com.hsofttec.intellij.querytester.services.ConnectionService; import com.hsofttec.intellij.querytester.ui.EventBusFactory; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.ComboBox; import com.intellij.ui.CollectionComboBoxModel; @@ -43,10 +44,13 @@ public class MasterdataScopeSelect extends ComboBox implements ItemListener { private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); - private static final ConnectionService connectionService = ConnectionService.getInstance( ); + private static final ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( ); + private final List scopes = new ArrayList<>( ); + private final Project project; - public MasterdataScopeSelect( ) { + public MasterdataScopeSelect( Project project ) { + this.project = project; EVENT_BUS.register( this ); setModel( new CollectionComboBoxModel<>( scopes ) ); addItemListener( this ); @@ -60,7 +64,7 @@ public void setSelectedIndex( int index ) { @Subscribe public void documentAreaChangedEvent( DocumentAreaChangedEvent event ) { - Session session = connectionService.getSession( ); + Session session = CONNECTION_SERVICE.getSession( ); scopes.clear( ); setSelectedIndex( -1 ); if ( session != null ) { diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/NqlQueryTextbox.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/NqlQueryTextbox.java index a98e97f..76a82a4 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/NqlQueryTextbox.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/NqlQueryTextbox.java @@ -36,7 +36,6 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CustomShortcutSet; import com.intellij.openapi.project.Project; -import com.intellij.openapi.project.ProjectManager; import com.intellij.util.textCompletion.TextFieldWithCompletion; import org.jetbrains.annotations.NotNull; @@ -47,12 +46,14 @@ public class NqlQueryTextbox extends TextFieldWithCompletion { private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); - private static final ProjectManager PROJECT_MANAGER = ProjectManager.getInstance( ); - private static final Project PROJECT = PROJECT_MANAGER.getOpenProjects( )[ 0 ]; private static final SettingsState SETTINGS_STATE = SettingsService.getSettings( ); - public NqlQueryTextbox( ) { - super( PROJECT, new NqlCompletionProvider( ), "", false, true, true ); + private final Project project; + + public NqlQueryTextbox( Project project ) { + super( project, new NqlCompletionProvider( ), "", false, true, true ); + setBorder( BorderFactory.createEmptyBorder( ) ); + this.project = project; EVENT_BUS.register( this ); setFont( new Font( SETTINGS_STATE.getFontFace( ), Font.PLAIN, SETTINGS_STATE.getFontSize( ) ) ); Dimension preferredSize = getPreferredSize( ); diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/NscaleTable.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/NscaleTable.java index d29ea90..b65f438 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/NscaleTable.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/NscaleTable.java @@ -61,11 +61,12 @@ public class NscaleTable extends JBTable { private static final QueryService QUERY_SERVICE = OPEN_PROJECT.getService( QueryService.class ); private static final HistorySettingsService HISTORY_SETTINGS_SERVICE = HistorySettingsService.getSettings( OPEN_PROJECT ); private static final SettingsState SETTINGS = SettingsService.getSettings( ); + private final Project project; - public NscaleTable( ) { + public NscaleTable( Project project ) { + this.project = project; EVENT_BUS.register( this ); setFont( new Font( SETTINGS.getFontFace( ), Font.PLAIN, SETTINGS.getFontSize( ) ) ); -// setBorder( BorderFactory.createEmptyBorder( ) ); setAutoResizeMode( JBTable.AUTO_RESIZE_OFF ); setDefaultRenderer( Object.class, new DynaPropertyTableCellRenderer( ) ); addMouseListener( new MouseAdapter( ) { @@ -74,10 +75,12 @@ public void mousePressed( MouseEvent mouseEvent ) { // selects the row at which point the mouse is clicked Point point = mouseEvent.getPoint( ); int currentRow = rowAtPoint( point ); - try { - setRowSelectionInterval( currentRow, currentRow ); - } catch ( Exception e ) { - logger.warn( ExceptionUtils.getRootCause( e ).getLocalizedMessage( ) ); + if ( currentRow > -1 ) { + try { + setRowSelectionInterval( currentRow, currentRow ); + } catch ( Exception e ) { + logger.warn( ExceptionUtils.getRootCause( e ).getLocalizedMessage( ) ); + } } } } ); @@ -91,12 +94,13 @@ public void fontSettingsChanged( FontSettingsChangedEvent event ) { @Subscribe public void startQueryExecution( StartQueryExecutionEvent event ) { - ProgressManager.getInstance( ).runProcessWithProgressSynchronously( ( ) -> { - ProgressIndicator progressIndicator = ProgressManager.getInstance( ).getProgressIndicator( ); - progressIndicator.setFraction( 0.1 ); + ProgressManager progressManager = ProgressManager.getInstance( ); + progressManager.runProcessWithProgressSynchronously( ( ) -> { + final ProgressIndicator progressIndicator = progressManager.getProgressIndicator( ); + progressIndicator.setText( "Execute query ..." ); + StartQueryExecutionEvent.QueryExecutionParameters queryExecutionParameters = event.getData( ); - progressIndicator.setFraction( 0.8 ); NscaleResult nscaleResult = QUERY_SERVICE.proccessQuery( queryExecutionParameters.getConnectionSettings( ), queryExecutionParameters.getQueryMode( ), queryExecutionParameters.getDocumentAreaName( ), @@ -117,8 +121,7 @@ public void startQueryExecution( StartQueryExecutionEvent event ) { } HISTORY_SETTINGS_SERVICE.addQuery( event.getData( ).getNqlQuery( ) ); } - progressIndicator.setFraction( 1.0 ); - }, "Executing query", true, OPEN_PROJECT ); + }, "Executing query", true, project ); } diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/ReconnectIcon.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ReconnectIcon.java new file mode 100644 index 0000000..6bddacf --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/ReconnectIcon.java @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.ui.components; + +import com.hsofttec.intellij.querytester.models.ConnectionSettings; +import com.intellij.icons.AllIcons; +import com.intellij.ui.roots.IconActionComponent; + +public class ReconnectIcon extends IconActionComponent { + public ReconnectIcon( ConnectionSelect connectionSelect ) { + super( AllIcons.Actions.Refresh, null, "Re-connect", ( ) -> { + if ( connectionSelect.getSelectedIndex( ) > -1 ) { + connectionSelect.checkOnlineState( ( ConnectionSettings ) connectionSelect.getSelectedItem( ) ); + } + } ); + } +} diff --git a/src/main/java/com/hsofttec/intellij/querytester/ui/components/RepositoryRootTextField.java b/src/main/java/com/hsofttec/intellij/querytester/ui/components/RepositoryRootTextField.java index 29ed0e6..74def89 100644 --- a/src/main/java/com/hsofttec/intellij/querytester/ui/components/RepositoryRootTextField.java +++ b/src/main/java/com/hsofttec/intellij/querytester/ui/components/RepositoryRootTextField.java @@ -28,6 +28,7 @@ import com.hsofttec.intellij.querytester.events.PrepareQueryExecutionEvent; import com.hsofttec.intellij.querytester.ui.EventBusFactory; import com.intellij.icons.AllIcons; +import com.intellij.openapi.project.Project; import com.intellij.ui.components.fields.ExtendableTextComponent; import com.intellij.ui.components.fields.ExtendableTextField; @@ -37,7 +38,10 @@ public class RepositoryRootTextField extends ExtendableTextField implements KeyListener { private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( ); - public RepositoryRootTextField( ) { + private final Project project; + + public RepositoryRootTextField( Project project ) { + this.project = project; EVENT_BUS.register( this ); addKeyListener( this ); ExtendableTextComponent.Extension browseExtension = diff --git a/src/main/java/com/hsofttec/intellij/querytester/utils/ConnectionTestTask.java b/src/main/java/com/hsofttec/intellij/querytester/utils/ConnectionTestTask.java new file mode 100644 index 0000000..143d6e4 --- /dev/null +++ b/src/main/java/com/hsofttec/intellij/querytester/utils/ConnectionTestTask.java @@ -0,0 +1,39 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2022 Sven Homburg, + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the “Software”), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package com.hsofttec.intellij.querytester.utils; + +import com.hsofttec.intellij.querytester.services.ConnectionService; + +public class ConnectionTestTask implements Runnable { + private final static ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( ); + public boolean useable = false; + + @Override + public void run( ) { +// if (CONNECTION_SERVICE.isConnectionUsable( ) + } + + +}