Skip to content

Commit

Permalink
重构和优化。
Browse files Browse the repository at this point in the history
重构代码:
        使代码层级更清楚,使新增功能更容易。
        优化了生成代码逻辑。
        抽离第三方代码。

优化体验:
        修正#47 :丰富了Field 属性在比较时候的条件
        生成的时候尽量不卡住主线程。

新增  split generate 模式:
        支持将依赖类生成在同一个包下,而不以静态内部类的形式存在。
  • Loading branch information
zzz40500 committed Nov 7, 2016
1 parent 7924b70 commit 2844788
Show file tree
Hide file tree
Showing 52 changed files with 1,909 additions and 1,217 deletions.
Expand Up @@ -64,9 +64,9 @@ of this software and associated documentation files (the "Software"), to deal
* before the closing bracket.</li>
* <li>The <code>null</code> value will be inserted when there is <code>,</code>
* &nbsp;<small>(comma)</small> elision.</li>
* <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single
* <li>Constant may be quoted with <code>'</code>&nbsp;<small>(single
* quote)</small>.</li>
* <li>Strings do not need to be quoted at all if they do not begin with a quote
* <li>Constant do not need to be quoted at all if they do not begin with a quote
* or single quote, and if they do not contain leading or trailing spaces, and
* if they do not contain any of these characters:
* <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and
Expand Down
File renamed without changes.
Expand Up @@ -73,9 +73,9 @@ of this software and associated documentation files (the "Software"), to deal
* <ul>
* <li>An extra <code>,</code>&nbsp;<small>(comma)</small> may appear just
* before the closing brace.</li>
* <li>Strings may be quoted with <code>'</code>&nbsp;<small>(single
* <li>Constant may be quoted with <code>'</code>&nbsp;<small>(single
* quote)</small>.</li>
* <li>Strings do not need to be quoted at all if they do not begin with a
* <li>Constant do not need to be quoted at all if they do not begin with a
* quote or single quote, and if they do not contain leading or trailing
* spaces, and if they do not contain any of these characters:
* <code>{ } [ ] / \ : , #</code> and if they do not look like numbers and
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -4,19 +4,18 @@
*/
package cn.vearn.checktreetable;

import org.gsonformat.intellij.entity.FieldEntity;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
import org.jdesktop.swingx.treetable.TreeTableNode;
import org.jdesktop.swingx.ux.CellProvider;

/**
*
* @author vearn
*/
public class FiledTreeTableModel extends DefaultTreeTableModel {

private String[] _names = {" Key ", "Value", "Data Type"," Field name "};
private Class[] _types = {Object.class,Object.class, Object.class, Object.class};
private String[] _names = {" Key ", "Value", "Data Type", " Field name "};
private Class[] _types = {Object.class, Object.class, Object.class, Object.class};


public FiledTreeTableModel(TreeTableNode node) {
Expand Down Expand Up @@ -52,26 +51,14 @@ public String getColumnName(int column) {
*/
@Override
public Object getValueAt(Object node, int column) {
Object value = null;
Object value = "";
if (node instanceof DefaultMutableTreeTableNode) {
DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node;
Object o = mutableNode.getUserObject();
if (o != null && o instanceof FieldEntity) {
FieldEntity bean = (FieldEntity) o;
switch (column) {
case 0:
value = bean.getKey();
break;
case 1:
value = bean.getValue();
break;
case 2:
value = bean.getRealType();
break;
case 3:
value = bean.getFieldName();
break;
}
if (o != null && o instanceof CellProvider) {
CellProvider cellProvider = (CellProvider) o;
value = cellProvider.getCellTitle(column);

}
}
return value;
Expand All @@ -80,35 +67,25 @@ public Object getValueAt(Object node, int column) {
@Override
public void setValueAt(Object value, Object node, int column) {
super.setValueAt(value, node, column);

if (node instanceof DefaultMutableTreeTableNode) {
DefaultMutableTreeTableNode mutableNode = (DefaultMutableTreeTableNode) node;
Object o = mutableNode.getUserObject();
if (o != null && o instanceof FieldEntity) {
FieldEntity bean = (FieldEntity) o;
switch (column) {
case 2:
bean.checkAndSetType(value.toString());
break;
case 3:
bean.setFieldName(value.toString());
break;
}
if (o != null && o instanceof CellProvider) {
CellProvider cellProvider = (CellProvider) o;

cellProvider.setValueAt(column,value.toString());
}
}
}


@Override
public boolean isCellEditable(Object node, int column) {

if(column == 2){

return true;
if (column == 2) {
return true;
}
if(column == 3){

return true;
if (column == 3) {
return true;
}
return false;
}
Expand Down
@@ -0,0 +1,11 @@
package org.jdesktop.swingx.ux;

/**
* Created by dim on 16/11/7.
*/
public interface CellProvider {

String getCellTitle(int index);

void setValueAt(int column, String text);
}
Expand Up @@ -11,6 +11,7 @@
import javax.swing.tree.TreePath;

import org.gsonformat.intellij.entity.FieldEntity;
import org.gsonformat.intellij.entity.ClassEntity;
import org.jdesktop.swingx.renderer.CellContext;
import org.jdesktop.swingx.renderer.ComponentProvider;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
Expand Down Expand Up @@ -40,7 +41,10 @@ protected void format(CellContext arg0) {
Object obj = node.getUserObject();
if(obj instanceof FieldEntity){
_label.setText(((FieldEntity) obj).getKey());
_checkBox.setFieldEntity((FieldEntity) obj);
_checkBox.setSelector((FieldEntity) obj);
}else if(obj instanceof ClassEntity){
_label.setText(((ClassEntity) obj).getClassName());
_checkBox.setSelector((ClassEntity) obj);
}

// _label.setIcon(arg0.getIcon());
Expand Down
10 changes: 10 additions & 0 deletions ThirdParty/treetable/java/src/org/jdesktop/swingx/ux/Selector.java
@@ -0,0 +1,10 @@
package org.jdesktop.swingx.ux;

/**
* Created by dim on 16/11/7.
*/
public interface Selector {

void setSelect(boolean select);

}
Expand Up @@ -4,7 +4,6 @@
*/
package org.jdesktop.swingx.ux;

import org.gsonformat.intellij.entity.FieldEntity;

import javax.swing.*;
import javax.swing.event.ChangeListener;
Expand All @@ -31,15 +30,12 @@ public class TristateCheckBox extends JCheckBox {

private final TristateDecorator decorator;

private FieldEntity fieldEntity;
private Selector selector;


public FieldEntity getFieldEntity() {
return fieldEntity;
}

public void setFieldEntity(FieldEntity fieldEntity) {
this.fieldEntity = fieldEntity;
public void setSelector(Selector selector) {
this.selector = selector;
}

public TristateCheckBox(String text, Icon icon, Boolean initial) {
Expand Down Expand Up @@ -118,24 +114,24 @@ private TristateDecorator(ButtonModel other) {
private void setState(Boolean state) {
if (state == Boolean.FALSE) {
other.setArmed(false);
if(fieldEntity != null){
fieldEntity.setGenerate(false);
if(selector != null){
selector.setSelect(false);
}
setPressed(false);
setSelected(false);
} else if (state == Boolean.TRUE) {
other.setArmed(false);
setPressed(false);
setSelected(true);
if(fieldEntity != null){
fieldEntity.setGenerate(true);
if(selector != null){
selector.setSelect(true);
}
} else {
other.setArmed(true);
setPressed(true);
setSelected(true);
if(fieldEntity != null){
fieldEntity.setGenerate(true);
if(selector != null){
selector.setSelect(true);
}

}
Expand Down
14 changes: 14 additions & 0 deletions build.gradle
Expand Up @@ -9,7 +9,20 @@ plugins {

apply plugin: 'org.jetbrains.intellij'
apply plugin: 'java'
// dependencies {
// compile project(':ThirdPart:checktreetable')
// compile project(':ThirdPart:json')
// }
println("${project.rootDir.absolutePath}")
sourceSets {
main {
java {
srcDir "${project.rootDir.absolutePath}/ThirdParty/json/java/src"
srcDir "${project.rootDir.absolutePath}/ThirdParty/treetable/java/src"
}

}
}
intellij {
version 'IC-2016.2.5'
pluginName 'GsonFormat'
Expand All @@ -24,3 +37,4 @@ intellij {
// Uncomment to test against Android Studio
// intellij.alternativeIdePath = '/Applications/Android Studio.app'
}

12 changes: 12 additions & 0 deletions local.properties
@@ -0,0 +1,12 @@
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Nov 07 18:38:05 CST 2016
ndk.dir=/Users/didm/android/sdk/ndk-bundle
sdk.dir=/Users/didm/android/sdk
2 changes: 1 addition & 1 deletion settings.gradle
Expand Up @@ -15,5 +15,5 @@ include 'shared'
include 'api'
include 'services:webservice'
*/

// include ':ThirdPart:checktreetable',':ThirdPart:json'
rootProject.name = 'GsonFormat'

0 comments on commit 2844788

Please sign in to comment.