程序员人生 网站导航

搜索对话框字符串过滤

栏目:互联网时间:2014-10-08 20:32:01
package com.sunsheen.ids.composite.dialog.select;


import java.util.ArrayList;
import java.util.Map;


import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Widget;


import com.sunsheen.ids.composite.dialog.FileViewer;
import com.sunsheen.ids.composite.utils.IdsUtils;
import com.sunsheen.jfids.studio.dialog.compoments.listeners.SDialogOnClickListener;


public class onChange implements SDialogOnClickListener {


@Override
public void run(Map<String, Widget> coms, Map<String, Object> params,
Event event, String currentKey) {
Text fileNameText=(Text)coms.get("fileName");
String fileName=fileNameText.getText().trim();
List colum=(List)coms.get("show");
String blank[]=new String[0];
colum.setItems(blank);//清空列表;
Label showText=(Label)coms.get("showText");
showText.setText("");//清空显示
//show0是临时添加,用来保存文件列表;
if(params.get("show0")==null)
{
java.util.List<String> list = new FileViewer().getListFiles(params.get("path").toString(), "java", true);
String[] arr = (String[]) list.toArray(new String[list.size()]);
params.put("show0", arr);
}

String []arr=(String[]) params.get("show0");
if(fileName.length()!=0)
{
//在正则表达式中,这些特殊符?,*等,是表示重复次数,前面必须有一个字符。但我们的要求是输入*就表示任意多个字符,所以要转化;
if(fileName.contains("?"))
{
// ?本身在正则表达式是为特殊,所以要转成字符串加? 才表示字符串中的? 。因为replaceAll中两个参数为正则表达式。
fileName=fileName.replaceAll("?", ".?");
}
if(fileName.contains("*"))
{
fileName=fileName.replaceAll("*", ".*");
}
for(int i=0;i<arr.length;i++)
{
String str=arr[i].substring(arr[i].lastIndexOf("")+1,arr[i].length());
if(str.toLowerCase().matches(".*"+fileName.toLowerCase()+".*"))//matches是全额匹配,所以前后加.*,表示任意多个字符
{
//全路径为:f:,但js引用是/,所以得转换
String path=(String) params.get("path");//工程路径;
String fullPath=arr[i].replaceAll("\", "/");
String path1=fullPath.substring(path.length()+1,fullPath.length());
colum.add(str+" - "+path1);
}
}
}
}
}
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐