You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
197 lines
6.0 KiB
197 lines
6.0 KiB
package com.fr.design.data.datapane; |
|
|
|
import com.fr.base.BaseUtils; |
|
import com.fr.base.svg.IconUtils; |
|
import com.fr.base.svg.SVGLoader; |
|
import com.fr.data.impl.DBTableData; |
|
import com.fr.design.actions.tabledata.TableDataAction; |
|
import com.fr.design.beans.BasicBeanPane; |
|
import com.fr.design.gui.controlpane.NameObjectCreator; |
|
import com.fr.design.gui.controlpane.UnrepeatedNameHelper; |
|
import com.fr.design.icon.WarningIcon; |
|
import com.fr.general.ComparatorUtils; |
|
import com.fr.general.NameObject; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.stable.ArrayUtils; |
|
import com.fr.stable.Nameable; |
|
import com.fr.stable.StringUtils; |
|
|
|
import javax.swing.Icon; |
|
import java.awt.Image; |
|
import java.text.Collator; |
|
import java.util.ArrayList; |
|
import java.util.Arrays; |
|
import java.util.List; |
|
|
|
/** |
|
* Created by IntelliJ IDEA. |
|
* Author : daisy |
|
* Version: 6.5.6 |
|
* Date: 13-12-20 |
|
* Time: 上午9:55 |
|
*/ |
|
public class TableDataNameObjectCreator extends NameObjectCreator { |
|
private boolean b = false; |
|
private Image menuImage; |
|
private String iconPath; |
|
private boolean isNeedInsertSeparator = false; |
|
private String prefix = ""; |
|
private java.util.List<String> names = new ArrayList<String>(); |
|
|
|
public TableDataNameObjectCreator(TableDataAction action) { |
|
super(action.getDisplayName(), action.getIconPath(), action.getTableDataClass(), action.getUpdateTableDataPaneClass()); |
|
this.iconPath = action.getIconPath(); |
|
menuImage = SVGLoader.load(iconPath); |
|
isNeedInsertSeparator = action.isNeedInsertSeparator(); |
|
prefix = action.getPrefix(); |
|
} |
|
|
|
public TableDataNameObjectCreator(TableDataAction action, Class clazz4Init) { |
|
super(action.getDisplayName(), action.getIconPath(), action.getTableDataClass(), clazz4Init, action.getUpdateTableDataPaneClass()); |
|
isNeedInsertSeparator = action.isNeedInsertSeparator(); |
|
prefix = action.getPrefix(); |
|
} |
|
|
|
public TableDataNameObjectCreator(String menuName, String iconPath, Class clazz, Class<? extends BasicBeanPane> updatePane) { |
|
super(menuName, iconPath, clazz, updatePane); |
|
if (iconPath != null) { |
|
this.iconPath = iconPath; |
|
menuImage = SVGLoader.load(iconPath); |
|
} |
|
} |
|
|
|
public TableDataNameObjectCreator(String menuName, String prefix, String iconPath, Class clazz, Class<? extends BasicBeanPane> updatePane) { |
|
super(menuName, iconPath, clazz, updatePane); |
|
if (iconPath != null) { |
|
this.iconPath = iconPath; |
|
menuImage = SVGLoader.load(iconPath); |
|
} |
|
this.prefix = prefix; |
|
} |
|
|
|
public TableDataNameObjectCreator(String menuName, String iconPath, Class clazz, Class clazz4Init, Class<? extends BasicBeanPane> updatePane) { |
|
super(menuName, iconPath, clazz, clazz4Init, updatePane); |
|
if (iconPath != null) { |
|
this.iconPath = iconPath; |
|
menuImage = SVGLoader.load(iconPath); |
|
} |
|
} |
|
|
|
public TableDataNameObjectCreator(String menuName, String prefix, String iconPath, Class clazz, Class clazz4Init, Class<? extends BasicBeanPane> updatePane) { |
|
super(menuName, iconPath, clazz, clazz4Init, updatePane); |
|
if (iconPath != null) { |
|
this.iconPath = iconPath; |
|
menuImage = SVGLoader.load(iconPath); |
|
} |
|
this.prefix = prefix; |
|
} |
|
|
|
|
|
@Override |
|
protected void doSthChanged4Icon(Object ob) { |
|
if (ob instanceof DBTableData) { |
|
DBTableData db = (DBTableData) ob; |
|
b = StringUtils.isBlank(db.getQuery()); |
|
} |
|
} |
|
|
|
/** |
|
* 取得菜单的图片 |
|
* |
|
* @return 图片 |
|
*/ |
|
@Override |
|
public Icon menuIcon() { |
|
return createMenuIcon(); |
|
} |
|
|
|
public String getIconPath() { |
|
return iconPath; |
|
} |
|
|
|
private Icon createMenuIcon() { |
|
return b ? new WarningIcon(this.menuImage) : this.menuIcon; |
|
} |
|
|
|
/** |
|
* 创建提示 |
|
* |
|
* @return 提示 |
|
*/ |
|
@Override |
|
public String createTooltip() { |
|
return b ? com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Connect_SQL_Cannot_Null") : null; |
|
} |
|
|
|
public String getPrefix() { |
|
return StringUtils.isNotBlank(prefix) ? prefix : menuName(); |
|
} |
|
|
|
/** |
|
* 将names排序 |
|
* |
|
* @return |
|
*/ |
|
public List<String> getNames() { |
|
String[] namearray = names.toArray(ArrayUtils.EMPTY_STRING_ARRAY); |
|
Arrays.sort(namearray, Collator.getInstance(java.util.Locale.CHINA)); |
|
return Arrays.asList(namearray); |
|
} |
|
|
|
public Object createObject() { |
|
try { |
|
return clazzOfObject.newInstance(); |
|
} catch (InstantiationException e) { |
|
try { |
|
return clazzOfInitCase.newInstance(); |
|
} catch (InstantiationException | IllegalAccessException e1) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
} |
|
} catch (IllegalAccessException e) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
} |
|
return null; |
|
} |
|
|
|
/** |
|
* 加入名字 |
|
* |
|
* @param names 名字 |
|
*/ |
|
public void addNames(String names) { |
|
if (names != null) { |
|
this.names.add(names); |
|
} |
|
} |
|
|
|
/** |
|
* 清除 |
|
*/ |
|
public void clear() { |
|
this.names.clear(); |
|
} |
|
|
|
public boolean shouldInsertSeparator() { |
|
return false; |
|
} |
|
|
|
@Override |
|
public boolean equals(Object obj) { |
|
return obj instanceof TableDataNameObjectCreator |
|
&& ComparatorUtils.equals(menuName, ((TableDataNameObjectCreator) obj).menuName); |
|
} |
|
|
|
@Override |
|
public Nameable createNameable(UnrepeatedNameHelper helper) { |
|
try { |
|
return new NameObject(helper.createUnrepeatedName(this.getPrefix()), clazzOfInitCase.newInstance()); |
|
} catch (InstantiationException | IllegalAccessException e) { |
|
throw new RuntimeException(e); |
|
} |
|
} |
|
|
|
@Override |
|
public int hashCode() { |
|
return menuName == null ? 0 : menuName.hashCode(); |
|
} |
|
} |