Skip to content

Commit

Permalink
- replace using raw EventBus against Jetbrain's MessageBus
Browse files Browse the repository at this point in the history
- enable cell editing
  • Loading branch information
S.Homburg authored and S.Homburg committed Oct 6, 2022
1 parent 60d6d80 commit d43690e
Show file tree
Hide file tree
Showing 31 changed files with 948 additions and 365 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ changelog {

dependencies {
implementation 'commons-beanutils:commons-beanutils:1.9.4'
implementation 'com.github.lgooddatepicker:LGoodDatePicker:11.2.1'
implementation("com.ceyoniq.nscale.applicationlayer:al-advanced-connector:8.2.1100") {
exclude group: "org.slf4j"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@

import com.ceyoniq.nscale.al.core.Session;
import com.ceyoniq.nscale.al.core.cfg.IndexingPropertyDefinition;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.hsofttec.intellij.querytester.events.DocumentAreaChangedEvent;
import com.hsofttec.intellij.querytester.services.ConnectionService;
import com.hsofttec.intellij.querytester.ui.EventBusFactory;
import com.hsofttec.intellij.querytester.utils.NqlLiterals;
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
Expand All @@ -45,16 +43,12 @@
public class NqlCompletionProvider extends TextFieldCompletionProviderDumbAware {
private static final ConnectionService CONNECTION_SERVICE = ConnectionService.getInstance( );

private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( );
;

private Pattern pattern = Pattern.compile( "([.!? ,])" );

private final List<IndexingPropertyDefinition> indexingPropertyDefinitions = new ArrayList<>( );

public NqlCompletionProvider( ) {
super( true );
EVENT_BUS.register( this );
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
package com.hsofttec.intellij.querytester.models;
/*
* The MIT License (MIT)
*
* Copyright © 2022 Sven Homburg, <homburgs@gmail.com>
*
* 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.
*/

import com.hsofttec.intellij.querytester.QueryTesterConstants;
package com.hsofttec.intellij.querytester.models;

import javax.swing.table.AbstractTableModel;

Expand All @@ -13,11 +35,7 @@ public DynaClassTableModel( NscaleResult result ) {

@Override
public String getColumnName( int column ) {
String colName = result.getPropertyNames( ).get( column );
if ( colName.equals( QueryTesterConstants.DBEAN_PROPERTY_NAME_LINENO ) ) {
colName = "";
}
return colName;
return result.getPropertyNames( ).get( column );
}

@Override
Expand All @@ -30,8 +48,14 @@ public int getColumnCount( ) {
return result.getPropertyNames( ).size( );
}


@Override
public Object getValueAt( int rowIndex, int columnIndex ) {
return result.getDynaBeans( ).get( rowIndex );
}

@Override
public boolean isCellEditable( int rowIndex, int columnIndex ) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
/*
* The MIT License (MIT)
*
* Copyright © 2022 Sven Homburg, <homburgs@gmail.com>
*
* 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.ceyoniq.nscale.al.core.common.ObjectclassName;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.joda.time.DateTime;
import org.joda.time.YearMonthDay;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class DynaPropertyTableCellRenderer extends DefaultTableCellRenderer {
@Override
Expand All @@ -23,48 +50,61 @@ public Component getTableCellRendererComponent( JTable table,
if ( value instanceof DynaBean ) {
DynaBean dynaBean = ( DynaBean ) value;
DynaProperty dynaProperty = dynaBean.getDynaClass( ).getDynaProperties( )[ column ];
Object dynaBeanValue = dynaBean.get( dynaProperty.getName( ) );
Class<?> type = dynaProperty.getType( );
if ( dynaBeanValue == null ) {
if ( ArrayList.class.equals( type ) ) {
value = "<Empty>";
} else {
value = "<null>";
}
} else if ( String.class.equals( type ) ) {
value = dynaBeanValue;
} else if ( ObjectclassName.class.equals( type ) ) {
value = ( ( ObjectclassName ) dynaBeanValue ).getName( );
} else if ( Integer.class.equals( type ) ) {
value = dynaBeanValue;
} else if ( Long.class.equals( type ) ) {
value = dynaBeanValue;
} else if ( DateTime.class.equals( type ) ) {
value = ( ( DateTime ) dynaBeanValue ).toString( "yyyy-MM-dd hh:mm:ss" );
} else if ( Boolean.class.equals( type ) ) {
value = ( ( Boolean ) dynaBeanValue ).toString( );
} else if ( ArrayList.class.equals( type ) ) {
ArrayList arrayList = ( ( ArrayList ) dynaBeanValue );
value = convertValueToString( dynaBean.get( dynaProperty.getName( ) ) );
}

return super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
}

private String convertValueToString( Object rawValue ) {
String stringValue = "";

if ( rawValue == null ) {
stringValue = "null";
} else {
if ( rawValue instanceof ArrayList ) {
List arrayList = ( ( ArrayList ) rawValue );
if ( arrayList.isEmpty( ) ) {
value = "<Empty>";
stringValue = "<Empty>";
} else {
StringBuilder valueBuilder = new StringBuilder( );
StringBuilder valueBuilder = new StringBuilder( "[" );
for ( Object element : arrayList ) {
if ( element == null ) {
element = "<null>";
valueBuilder.append( "<null>" );
} else {
valueBuilder.append( convertValueToString( element ) ).append( ";" );
}
valueBuilder.append( element ).append( ";" );
}
value = valueBuilder.toString( );
if ( ( ( String ) value ).length( ) > 0 ) {
value = StringUtils.stripEnd( ( String ) value, ";" );

if ( !arrayList.isEmpty( ) ) {
valueBuilder.deleteCharAt( valueBuilder.length( ) - 1 );
}

valueBuilder.append( "]" );
stringValue = valueBuilder.toString( );
}
} else if ( rawValue instanceof ObjectclassName ) {
stringValue = ( ( ObjectclassName ) rawValue ).getName( );
} else if ( rawValue instanceof DateTime ) {
stringValue = ( ( DateTime ) rawValue ).toString( "yyyy-MM-dd hh:mm:ss" );
} else if ( rawValue instanceof Date ) {
stringValue = DateFormatUtils.format( ( Date ) rawValue, "yyyy-MM-dd" );
} else if ( rawValue instanceof YearMonthDay ) {
stringValue = ( ( YearMonthDay ) rawValue ).toString( "yyyy-MM-dd" );
} else if ( rawValue instanceof Boolean ) {
stringValue = ( ( Boolean ) rawValue ).toString( );
} else if ( rawValue instanceof Integer ) {
stringValue = ( ( Integer ) rawValue ).toString( );
} else if ( rawValue instanceof Double ) {
stringValue = ( ( Double ) rawValue ).toString( );
} else if ( rawValue instanceof Long ) {
stringValue = ( ( Long ) rawValue ).toString( );
} else {
value = dynaBeanValue.toString( );
stringValue = String.valueOf( rawValue );
}
}

return super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
return stringValue;
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
/*
* The MIT License (MIT)
*
* Copyright © 2022 Sven Homburg, <homburgs@gmail.com>
*
* 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;

import com.google.common.eventbus.EventBus;
import com.hsofttec.intellij.querytester.events.FontSettingsChangedEvent;
import com.hsofttec.intellij.querytester.models.SettingsState;
import com.hsofttec.intellij.querytester.services.SettingsService;
import com.hsofttec.intellij.querytester.ui.components.AppSettingsComponent;
import com.hsofttec.intellij.querytester.ui.notifiers.FontSettingsChangedNotifier;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.util.messages.MessageBus;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

public class AppSettingsConfigurable implements Configurable {
private AppSettingsComponent appSettingsComponent;

private static final EventBus EVENT_BUS = EventBusFactory.getInstance( ).get( );
;
private MessageBus messageBus;

@Nls( capitalization = Nls.Capitalization.Title )
@Override
Expand All @@ -31,7 +55,9 @@ public JComponent getPreferredFocusedComponent( ) {
@Nullable
@Override
public JComponent createComponent( ) {
appSettingsComponent = new AppSettingsComponent( );
Project project = ProjectManager.getInstance( ).getOpenProjects( )[ 0 ];
messageBus = project.getMessageBus( );
appSettingsComponent = new AppSettingsComponent( project );
return appSettingsComponent.getPanel( );
}

Expand All @@ -56,7 +82,8 @@ public void apply( ) {
settings.setMaxResultSize( appSettingsComponent.getMaxResultSizeValue( ) );
settings.setFontFace( appSettingsComponent.getFontFaceValue( ) );
settings.setFontSize( appSettingsComponent.getFontSizeValue( ) );
EVENT_BUS.post( new FontSettingsChangedEvent( ) );
FontSettingsChangedNotifier notifier = messageBus.syncPublisher( FontSettingsChangedNotifier.FONT_SETTINGS_CHANGED_TOPIC );
notifier.doAction( );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
/*
* The MIT License (MIT)
*
* Copyright © 2022 Sven Homburg, <homburgs@gmail.com>
*
* 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;

import com.google.common.eventbus.EventBus;
import com.intellij.openapi.project.ProjectManager;

public class EventBusFactory {
private static EventBusFactory instance = null;
private static final ProjectManager projectManager = ProjectManager.getInstance( );

private final EventBus eventBus;

Expand Down

This file was deleted.

Loading

0 comments on commit d43690e

Please sign in to comment.