NC65如何修改某一行的颜色

前言

NC65真恶心,文档太少了,希望我们开发人员都能分享自己的学习成果,共同进步,一起把这碗饭吃到肚子里

本次需求

甲方要求我们对数据进行预警,即比如10行数据,快要到期的数据要进行标识。比如这样颜色变红、或者字体颜色变红。

解决方法

1.拦截器
我先在配置文件defaultQueryAction中加了一个拦截器,试图在拦截器方法中的afterDoActionSuccessed方法拦截然后改变颜色,断点发现没用进入这个方法,所以失败

2.规则
个人感觉这个适合放在规则里面去配置,新增、删除有默认的规则。查询没用,还要写一套东西,我没去处理

3.打开节点监听
最后我用这个方法处理的,先上效果:
这个是字体变色的效果

具体代码

1.配置文件

		<!-- 打开节点监听 newadd-->
	<bean id="InitDataListener" class="nc.ui.hd.hazardenter.ace.handler.MyDefaultFuncNodeInitDataListener">
		<property name="model" ref="bmModel"/>
		<property name="context" ref="context"></property>
		<property name="voClassName" value="nc.vo.hd.hazardenter.AggHazardHVO"/>
		<property name="billform" ref="billForm"></property>
		<property name="listView" ref="billListView" />
		<property name="defaultUIF2RefEditor">
			<ref bean="defaultUIF2RefEditor" />
		</property>
	</bean>
	
	<!-- 导入编辑器 -->
	<bean id="defaultUIF2RefEditor" class="nc.itf.hd.DefaultUIF2RefEditor">
		<property name="addAction" ref="addAction" />
		<property name="billcardPanelEditor" ref="billForm" />
		<property name="appModel" ref="bmModel" />
	</bean>

2.MyDefaultFuncNodeInitDataListener

package nc.ui.hd.hazardenter.ace.handler;



import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumnModel;

import nc.funcnode.ui.FuncletInitData;
import nc.itf.hd.DefaultUIF2RefEditor;
import nc.ui.pubapp.uif2app.model.DefaultFuncNodeInitDataListener;
import nc.ui.pubapp.uif2app.view.BillListView;
import nc.ui.pubapp.uif2app.view.ShowUpableBillForm;

 
/**
 * 
 * @author: wangchao
 * @ClassName: MyDefaultFuncNodeInitDataListener 
 * @Description: 节点打开初始化数据
 * @date: 2022年12月29日
 */
public class MyDefaultFuncNodeInitDataListener extends DefaultFuncNodeInitDataListener {
 
	ShowUpableBillForm billform;
	private DefaultUIF2RefEditor defaultUIF2RefEditor = null;
	private BillListView listView;
	public MyDefaultFuncNodeInitDataListener(){
		super();
	}
	
	@Override
    public void initData(FuncletInitData data) {
		//新建列表现器
		DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
			public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
				Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
				if (table.getValueAt(row, column) != null) {
					String a = table.getValueAt(row, column).toString();
					if(a.equals("1001ZZ1000000021LOW7") || a.equals("待整改")) {
						cell.setForeground(Color.RED);
					}else{
						cell.setForeground(Color.BLACK);
					}
				}
				
				return cell;
			}
		};
		String str1 = listView.getBillListPanel().getHeadItem("hd_content").getName();
		listView.getBillListPanel().getHeadTable().getColumn(str1).setPreferredWidth(500);

		
    	TableColumnModel colModel = listView.getBillListPanel().getHeadTable().getColumnModel();
    	int icol = colModel.getColumnCount();
    	for(int i=0;i<icol;i++) {
    		colModel.getColumn(i).setCellRenderer(tcr);
    	}

}
	
	
	public ShowUpableBillForm getBillform() {
		return billform;
	}
	public void setBillform(ShowUpableBillForm billform) {
		this.billform = billform;
	}
	public DefaultUIF2RefEditor getDefaultUIF2RefEditor() {
		return defaultUIF2RefEditor;
	}
	public void setDefaultUIF2RefEditor(DefaultUIF2RefEditor defaultUIF2RefEditor) {
		this.defaultUIF2RefEditor = defaultUIF2RefEditor;
	}
    
	/*     */   public BillListView getListView() {
		/*  69 */     return listView;
		/*     */   }
		/*     */   
		/*     */   public void setListView(BillListView listView) {
		/*  81 */     this.listView = listView;
		/*     */   }
    
}

3.defaultUIF2RefEditor

package nc.itf.hd;


import nc.ui.pub.bill.BillData;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.editor.IBillCardPanelEditor;
import nc.ui.uif2.model.AbstractUIAppModel;
import nc.vo.pub.AggregatedValueObject;
 
 
 
public  class DefaultUIF2RefEditor  {
 
	
	
	private NCAction addAction = null;
									
	private Exception ex;    //保存过程中通过拦截器将异常抛出 
 
	
	private IBillCardPanelEditor billcardPanelEditor = null;
	
	private AbstractUIAppModel appModel = null;
	
 
	protected NCAction createAddAction()
	{
		return null;
	}
	
	protected NCAction createSaveAction()
	{
		return null;
	} 
	
	protected NCAction createCancelAction()
	{
		return null;
	}
	
	protected IBillCardPanelEditor createBillCardPanelEditor()
	{
		return null;
	}
	
	protected AbstractUIAppModel createAppModel()
	{
		return null;
	}
	
	
	 
	
	/**
	 * 新增操作
	 * 
	 * @see nc.itf.trade.excelimport.IImportableEditor#addNew()
	 */
	public void addNew() {
		try {
			getAddAction().actionPerformed(null);
		} catch (Exception e) {
			nc.bs.logging.Logger.error(e.getMessage());
		}
	} 
	
	/**
	 * 设值操作
	 * 
	 * 标准的操作步骤如下:
	 * 1,转型VO为ExtendedAggregatedValueObject
	 * 2,根据转换规则处理VO的相关属性值
	 * 3,将处理后的VO值设置到界面上
	 */
	public void setValue(Object obj) {
		if(getBillcardPanelEditor() != null)
		{
			BillData bd = getBillcardPanelEditor().getBillCardPanel().getBillData();
			bd.setBillValueVO((AggregatedValueObject)obj);
		}
	}
 
 
 
	
	/**
	 * 返回AddAction对象
	 */
	public NCAction getAddAction() {
		
		if(addAction == null)
			addAction = createAddAction();
		return this.addAction;
	}
 
	
 
	public void setAddAction(NCAction addAction) {
		this.addAction = addAction;
	}
 
	public IBillCardPanelEditor getBillcardPanelEditor() {
		
		if(billcardPanelEditor == null)
			billcardPanelEditor = createBillCardPanelEditor();
		return billcardPanelEditor;
	}
 
	public void setBillcardPanelEditor(IBillCardPanelEditor billcardPanelEditor) {
		this.billcardPanelEditor = billcardPanelEditor;
	}
 
 
 
	
	public AbstractUIAppModel getAppModel() {
		
		if(this.appModel == null)
			appModel = createAppModel();
		return appModel;
	}
 
	public void setAppModel(AbstractUIAppModel model) {
		this.appModel = model;
	}
	
	public int getExportCount() {
		return 1;
	}
 
	public Exception getEx() {
		return ex;
	}
 
	public void setEx(Exception ex) {
		this.ex = ex;
	}
}

代码说明

变色的主要逻辑在 MyDefaultFuncNodeInitDataListener.initData() 方法中,代码逻辑很简单自己看一下应该能明白

这两行代码控制表头列宽,具体实现效果看上面图片有一列变宽了。

		//这两行代码控制表头列宽
		String str1 = listView.getBillListPanel().getHeadItem("hd_content").getName();
		listView.getBillListPanel().getHeadTable().getColumn(str1).setPreferredWidth(500);
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值