Commit 6239bd3a authored by realize1020's avatar realize1020

京能结构化

京能结构化
parent ea10a413
package com.gx.obe.web.service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
......@@ -23,6 +24,7 @@ import com.gx.obe.web.vo.SaveSubBidPriceResultVo;
import com.gx.obe.web.vo.SaveSupplierInputBidPriceResultVo;
import com.gx.obe.web.vo.SaveSupplierInputEvaluationPriceResultVo;
import com.gx.obe.web.vo.UpdateAssignPropertyVo;
import com.gx.obe.web.utils.ObeHttpUtils;
/**
* @Description: 投标报价数据接口
......@@ -501,4 +503,21 @@ public class BidPriceResultService {
return false;
}
}
/**
* @Description: 修正投标报价
* @author chenxw
* @param id
* @param finalBidPrice
* @param modifyReason
* @return
*/
public boolean modifyBidPrice(String id, BigDecimal finalBidPrice, String modifyReason) {
Map<String, Object> param = new HashMap<String, Object>();
param.put("id", id);
param.put("finalBidPrice", finalBidPrice);
param.put("modifyReason", modifyReason);
return ObeHttpUtils.getBoolean(URL.concat("/modifyBidPrice"), param);
}
}
......@@ -51,4 +51,14 @@ public class ObeHttpUtils {
return new ArrayList<>();
}
public static boolean getBoolean(String path, Map<String, Object> param) {
String strWebServerUrl = Constants.getServiceUrl(path);
try {
return ResultStatus.getReultStatusBoolean(NetworkRequest.get(strWebServerUrl, param));
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
}
......@@ -68,3 +68,4 @@ Bundle-ClassPath: .,
lib/jackson-core-2.9.0.jar,
lib/jackson-databind-2.9.0.jar
Bundle-ActivationPolicy: lazy
Import-Package: com.gx.obe.datastruct.tree
......@@ -194,5 +194,20 @@ public class Constants {
public static final String TIANYAN_CHECK_NOTE = "TIANYAN_CHECK_NOTE.pdf";
public static String ETB = ".etb";// 电子投标文件
public static String EZG = ".etb";//".ezg";// 电子资格投标文件
public static String EZB = ".ezb";// 电子招标文件
public static String ECN = ".enc";
public static String ENC = ".enc";
public static String XLS = ".xls";
public static String PDF = ".pdf";
public static String DOC = ".doc";
public static String DOCX = ".docx";
public static String XML = ".xml";
public static String LOG = ".log";
public static String XLSX = ".xlsx";
public static String ZIP = ".zip";
}
......@@ -26,6 +26,8 @@ public class EvaluationStepEnum {
public static final String EDIT_PRICE = "17";// 价格评审
// public static final String REBIDPRICE = "18";// 再次报价
public static final String BUSINESS_VETO = "18";
public static final String APPRAISE_EXPERT = "19";// 评价专家
public static final String APPRAISE_MANAGER = "20";// 评价项目经理
public static final String FIXED_FACTOR = "21";// 定档
public static final String ASSOCIATION_QUERY = "22";// 关联查询评审步骤
......
......@@ -1826,3 +1826,5 @@ Yes=\u662F
You=\u60A8
ZipCode=\u90AE\u653F\u7F16\u7801
ips_noOpenLiveing=\u672A\u5F00\u542F\u76F4\u64AD\uFF01
Step_appraiseExpert=\u4e13\u5bb6\u8bc4\u4ef7
Step_appraiseManager=\u9879\u76ee\u7ecf\u7406\u8bc4\u4ef7
......@@ -1885,6 +1885,8 @@ public class Messages extends NLS {
public static String ips_noOpenLiveing;
public static String RecommonedEvaluationComposite_text_text;
public static String RecommonedEvaluationTableComposite_text_text;
public static String Step_appraiseExpert;
public static String Step_appraiseManager;
static {
// initialize resource bundle
......
......@@ -1826,3 +1826,5 @@ Yes=\u662F
You=\u60A8
ZipCode=\u90AE\u653F\u7F16\u7801
ips_noOpenLiveing=\u672A\u5F00\u542F\u76F4\u64AD\uFF01
Step_appraiseExpert=\u4e13\u5bb6\u8bc4\u4ef7
Step_appraiseManager=\u9879\u76ee\u7ecf\u7406\u8bc4\u4ef7
......@@ -56,4 +56,8 @@ public class Keys {
return get(2);
}
public static Keys of(Object... ks) {
return new Keys(ks);
}
}
......@@ -29,4 +29,27 @@ public class PredicateUtils {
return t -> predicate.test(function.apply(t));
}
/**
* @Description: 使用
* @author chenxw
* @param f
* @param p
* @return
*/
public static <T, R> Predicate<T> apply(Function<T, R> f, Predicate<R> p) {
return t -> p.test(f.apply(t));
}
/**
* @Description: 大于
* @author chenxw
* @param higher
* @return
*/
public static Predicate<Integer> higher(int higher) {
return t -> t > higher;
}
}
package com.gx.obe.util.utils;
import java.util.Map;
import com.gx.obe.util.utils.EnumUtils;
public enum TerminalUtils {
/**
* 项目管理
*/
TERMINAL_MANAGEMENT("00"),
/**
* 开标工具
*/
TERMINAL_BIDOPENING("01"),
/**
* 评标工具
*/
TERMINAL_EVALUATION("02"),
/**
* 系统管理
*/
TERMINAL_SYSTEM("03"),
/**
* 远程开标辅助工具
*/
TERMINAL_ASSISTOPENING("04"),
/**
* 监督管理
*/
TERMINAL_SUPERVISE("05");
private String key;
private static TerminalUtils terminalType;
private TerminalUtils(String key) {
this.key = key;
}
public static Map<String, TerminalUtils> map = EnumUtils.toMap(values(), TerminalUtils::getKey);
public String getKey() {
return key;
}
public static void setTerminalType(TerminalUtils terminalType) {
TerminalUtils.terminalType = terminalType;
}
public static TerminalUtils getTerminalType() {
return terminalType;
}
}
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Action
Bundle-SymbolicName: com.gx.obe.action;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.gx.obe.action.Activator
Bundle-Vendor: GX
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.gx.obe.utils,
com.gx.obe.components.core,
com.gx.obe.business,
com.gx.obe.component,
com.gx.obe.bind;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.gx.obe.action
Bundle-ActivationPolicy: lazy
Export-Package: com.gx.obe.action.bean,
com.gx.obe.action.listener
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
javacDefaultEncoding.. = UTF-8
\ No newline at end of file
package com.gx.obe.action;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.gx.obe.action"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
package com.gx.obe.action.bean;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.gx.obe.action.listener.ActionListener;
import com.gx.obe.util.utils.UuidUtils;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.ProjectRuleService;
import com.gx.obe.web.service.TenderProjectService;
/**
* @Description:封装公共action接口
* @author guoyr
*/
public abstract class Action {
private String id = UuidUtils.getUUID();
private ActionListener listener;
public abstract void run();
private Map<String, Object> data = null;
private TenderProjectEntity parentProject;
private TenderProjectEntity tenderProject;
private TenderProjectRuleEntity tenderProjectRule;
private TenderProjectService tenderProjectService;
private ProjectRuleService projectRuleService;
private EvaluationStep evaluationStep;
private Menu menu;
/**
* @Description: 添加action监听
* @author guoyr
* @param listener
*/
public void addActionListener(ActionListener listener){
this.listener = listener;
}
public TenderProjectEntity refreshParentProject() {
if(null == tenderProjectService){
tenderProjectService = new TenderProjectService();
}
parentProject = tenderProjectService.getById(parentProject.getId());
return parentProject;
}
public TenderProjectEntity refreshTenderProject() {
if(null == tenderProjectService){
tenderProjectService = new TenderProjectService();
}
tenderProject = tenderProjectService.getById(tenderProject.getId());
tenderProject.setParentProjectEntity(parentProject);
return tenderProject;
}
public TenderProjectRuleEntity refreshTenderProjectRule() {
if(null == projectRuleService){
projectRuleService = new ProjectRuleService();
}
// if(null != tenderProjectRule && null != tenderProjectRule.getId()){
// }
tenderProjectRule = projectRuleService.getProjectRule(tenderProject.getId());
if(null == tenderProjectRule) {
tenderProjectRule = new TenderProjectRuleEntity();
tenderProjectRule.setTenderId(tenderProject.getId());
tenderProjectRule.setId(UuidUtils.getUUID());
projectRuleService.insert(tenderProjectRule);
}
return tenderProjectRule;
}
/**
* @Description: 获取action监听
* @author guoyr
* @return
*/
public ActionListener getListener() {
return listener;
}
public Menu getMenu() {
return menu;
}
public void setMenu(Menu menu) {
this.menu = menu;
}
public TenderProjectEntity getParentProject() {
return parentProject;
}
public void setParentProject(TenderProjectEntity parentProject) {
this.parentProject = parentProject;
}
public TenderProjectEntity getTenderProject() {
return tenderProject;
}
public void setTenderProject(TenderProjectEntity tenderProject) {
this.tenderProject = tenderProject;
this.tenderProject.setParentProjectEntity(getParentProject());
}
public TenderProjectRuleEntity getTenderProjectRule() {
return tenderProjectRule;
}
public void setTenderProjectRule(TenderProjectRuleEntity tenderProjectRule) {
this.tenderProjectRule = tenderProjectRule;
}
public EvaluationStep getEvaluationStep() {
return evaluationStep;
}
public void setEvaluationStep(EvaluationStep evaluationStep) {
this.evaluationStep = evaluationStep;
}
/**
* @Description: 设置data数据
* @author guoyr
* @param key
* @param value
*/
public void setData(String key, Object value) {
if(data == null){
data = new HashMap<String, Object>();
}
data.put(key, value);
}
public Shell getParentShell(Shell parent){
if(null != parent && !parent.isDisposed()){
return parent;
}else {
Shell _parentShell = null;
_parentShell = Display.getDefault().getActiveShell();
if(null != _parentShell && !_parentShell.isDisposed()){
return _parentShell;
}else {
Shell[] shells = Display.getDefault().getShells();
if(null != shells && shells.length > 0){
for(int i = shells.length -1; i >= 0; i--){
if(null != shells[i] && !shells[i].isDisposed()){
return shells[i];
}
}
}
}
}
return new Shell(SWT.ON_TOP);
}
/**
* @Description: 获取data数据
* @author guoyr
* @param key
* @return
*/
public Object getData(String key) {
if(data != null){
return data.get(key);
}
return null;
}
@Override
public String toString() {
return id;
}
}
package com.gx.obe.action.bean;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.action.listener.ActionListener;
public abstract class CAction extends Action {
@Override
public void run() {
ActionListener listener = this.getListener();
listener.onLoad(this);
listener.loadComposite(this, initComposite(listener.getParentComposite()));
}
protected abstract Composite initComposite(Composite parent);
}
package com.gx.obe.action.bean;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.action.listener.ActionListener;
import com.gx.obe.component.rx.RxSwt;
public abstract class FAction<T> extends Action {
@Override
public void run() {
ActionListener listener = this.getListener();
listener.onLoad(this);
RxSwt.run(this::supply).checkWidget(listener.getParentComposite()).exe(this::loadComposite);
}
private void loadComposite(T t) {
ActionListener listener = this.getListener();
listener.loadComposite(this, consume(listener.getParentComposite(), t));
}
protected abstract T supply();
protected abstract Composite consume(Composite parent, T t);
}
package com.gx.obe.action.listener;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.action.bean.Action;
/**
* @Description: 公共的action监听接口
* @author guoyr
*/
public interface ActionListener{
/**
* @Description: 重载监听
* @author guoyr
*/
public void onLoad(Action action);
/**
* @Description: 面板加载监听
* @author guoyr
* @param action
* @param composite
*/
public void loadComposite(Action action, Composite composite);
/**
* @Description: 获取父级面板
* @author guoyr
* @return
*/
public Composite getParentComposite();
}
......@@ -30,3 +30,5 @@ Export-Package: com.gx.obe.answer,
com.gx.obe.answer.dataset,
com.gx.obe.answer.dialog,
com.gx.obe.answer.thread
Import-Package: com.gx.obe.action.bean,
com.gx.obe.action.utils
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bind
Bundle-SymbolicName: com.gx.obe.bind
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.gx.obe.bind.Activator
Bundle-Vendor: GX
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.gx.obe.bind
Bundle-ActivationPolicy: lazy
Export-Package: com.gx.obe.bind,
com.gx.obe.bind.base,
com.gx.obe.bind.call,
com.gx.obe.bind.exception,
com.gx.obe.bind.fun,
com.gx.obe.bind.promise,
com.gx.obe.bind.prop,
com.gx.obe.bind.recursion,
com.gx.obe.bind.rx,
com.gx.obe.bind.stream,
com.gx.obe.bind.utils,
com.gx.obe.bind.view
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
javacDefaultEncoding.. = UTF-8
\ No newline at end of file
package com.gx.obe.bind;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.gx.obe.bind"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
package com.gx.obe.bind.base;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.RView;
import com.gx.obe.bind.view.Write;
public class P<T> implements RView<T> {
private boolean log;
private T value;
private Map<String, BiConsumer<T, T>> writeMap = new HashMap<>();
private List<ChangeListener> changeListenerList = new ArrayList<>();
private String name;
private BiPredicate<T, T> predicate = (o, n) -> true;
private T defaultValue;
private Supplier<T> other = () -> defaultValue;
public P<T> as(String name) {
this.name = Objects.requireNonNull(name);
this.log = true;
return this;
}
public P<T> orElseGet(Supplier<T> other) {
this.other = Objects.requireNonNull(other);
this.value = other.get();
return this;
}
public P<T> orElse(T defaultValue) {
this.defaultValue = defaultValue;
this.value = defaultValue;
return this;
}
public P<T> limit(BiPredicate<T, T> predicate) {
this.predicate = Objects.requireNonNull(predicate);
return this;
}
public T get() {
return value;
}
public void bind(Write<T> write) {
bind(UUID.randomUUID().toString(), write);
}
public void bind(String key, Write<T> write) {
Objects.requireNonNull(write);
this.writeMap.put(key, (o, n) -> write.set(n));
}
public void watch(BiConsumer<T, T> biConsumer) {
watch(UUID.randomUUID().toString(), biConsumer);
}
public void watch(String key, BiConsumer<T, T> biConsumer) {
Objects.requireNonNull(biConsumer);
this.writeMap.put(key, biConsumer);
}
public void bindExe(Write<T> write) {
bindExe(UUID.randomUUID().toString(), write);
}
public void bindExe(String key, Write<T> write) {
Objects.requireNonNull(write);
write.set(value);
this.writeMap.put(key, (o, n) -> write.set(n));
}
public void clearBind() {
this.writeMap.clear();
this.value = other.get();
}
public void clearListener() {
this.changeListenerList.clear();
}
private void _change(T value) {
if (log) System.out.println(name + " --source:" + this.value + " --change:" + value);
this.value = Optional.ofNullable(value).orElseGet(other);
this.changeListenerList.forEach(ChangeListener::change);
}
protected void change(T value) {
T old = this.value;
if (!predicate.test(old, value)) return;
_change(value);
this.writeMap.values().stream().forEach(c -> c.accept(old, get()));
}
protected void change(T value, String key) {
T old = this.value;
if (!predicate.test(old, value)) return;
_change(value);
this.writeMap.entrySet().stream().filter(e -> !e.getKey().equals(key)).map(e -> e.getValue()).forEach(c -> c.accept(old, get()));
}
public boolean isBind() {
return !writeMap.isEmpty();
}
@Override
public void addChangeListener(ChangeListener changeListener) {
this.changeListenerList.add(Objects.requireNonNull(changeListener));
}
@Override
public String toString() {
return "P:" + Objects.toString(value);
}
}
package com.gx.obe.bind.call;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.gx.obe.bind.view.Read;
import com.gx.obe.bind.view.Write;
public class Call {
private final List<Callback> callbackList = new ArrayList<>();
public static Call of(Callback callback) {
return new Call().bind(callback);
}
public boolean isBind() {
return !callbackList.isEmpty();
}
public Call bind(Callback callback) {
callbackList.add(callback);
return this;
}
public Call bindExe(Callback callback) {
callback.call();
return bind(callback);
}
public void exe() {
callbackList.stream().forEach(Callback::call);
}
public <T> Consumer<T> toSet() {
return t -> exe();
}
public <T> Supplier<T> toGet() {
return () -> {
exe();
return null;
};
}
public <T> Write<T> toWrite() {
return t -> exe();
}
public <T> Read<T> toRead() {
return () -> {
exe();
return null;
};
}
}
package com.gx.obe.bind.call;
public interface Callback {
void call();
}
package com.gx.obe.bind.exception;
public interface ExFunction<T, R> {
R apply(T t) throws Exception;
}
package com.gx.obe.bind.exception;
import java.math.BigDecimal;
import java.util.function.Function;
public class ExceptionFun<T, R> implements Function<T, R> {
private ExFunction<T, R> function;
public static <T, R> ExceptionFun<T, R> of(ExFunction<T, R> function) {
return new ExceptionFun<>(function);
}
public ExceptionFun(ExFunction<T, R> function) {
this.function = function;
}
public R get(T t) {
return getOrDefault(t, null);
}
public R getOrDefault(T t, R defaultValue) {
try {
return function.apply(t);
} catch (Exception e) {
return defaultValue;
}
}
public R getOrThrow(T t) {
try {
return function.apply(t);
} catch (Exception e) {
throw new NullPointerException(e.getMessage());
}
}
public static final ExceptionFun<String, BigDecimal> toBigDecimal = of(BigDecimal::new);
public static final ExceptionFun<String, Integer> toInteger = of(Integer::valueOf);
@Override
public R apply(T t) {
return get(t);
}
}
package com.gx.obe.bind.fun;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import com.gx.obe.bind.view.Read;
import com.gx.obe.bind.view.Write;
public class Fun<T, R> {
private Function<T, R> function;
private Fun(Function<T, R> function) {
this.function = function;
}
public <V> Fun<T, V> andThen(Function<R, V> after) {
return Fun.of(function.andThen(after));
}
public <V> Fun<V, R> compose(Function<V, T> before) {
return Fun.of(function.compose(before));
}
public Function<T, R> toFun() {
return function;
}
public Supplier<R> toGet(T t) {
return () -> function.apply(t);
}
public Supplier<R> toGet(Supplier<T> supplier) {
return () -> function.apply(supplier.get());
}
public Read<R> toRead(T t) {
return () -> function.apply(t);
}
public Read<R> toRead(Read<T> read) {
return () -> function.apply(read.get());
}
public Consumer<T> toSet(Consumer<R> consumer) {
return t -> consumer.accept(function.apply(t));
}
public Write<T> toWrite(Consumer<R> consumer) {
return t -> consumer.accept(function.apply(t));
}
public Predicate<T> toTest(Predicate<R> predicate) {
return t -> predicate.test(function.apply(t));
}
public static <T, R> Fun<T, R> of(Function<T, R> function) {
return new Fun<>(function);
}
}
package com.gx.obe.bind.promise;
import java.util.function.Consumer;
import java.util.function.Function;
public class Promise<T> {
private STATUS status = STATUS.PENDING;
private T value;
private Exception error;
private Consumer<T> onFullFilled = t -> {};
private Consumer<Exception> onRejected = e -> {};
enum STATUS {
PENDING, RESOLVE, REJECT;
}
public Promise(Fun<T> fun) {
Consumer<T> resolve = t -> {
this.status = STATUS.RESOLVE;
this.value = t;
this.onFullFilled.accept(t);
synchronized (this) {
this.notify();
}
};
Consumer<Exception> reject = e -> {
this.status = STATUS.REJECT;
this.error = e;
this.onRejected.accept(e);
synchronized (this) {
this.notify();
}
};
try {
fun.call(resolve, reject);
} catch (Exception e) {
reject.accept(e);
}
}
public static <T> Promise<T> thread(Fun<T> fun) {
return new Promise<>((resolve, reject) -> {
new Thread(() -> {
try {
fun.call(resolve, reject);
} catch (Exception e) {
e.printStackTrace();
reject.accept(e);
}
}).start();
});
}
public static <T> Promise<T> empty() {
return new Promise<>((resolve, reject) -> {});
}
public static <T> Promise<T> resolve(T value) {
return new Promise<>((resolve, reject) -> resolve.accept(value));
}
public static <T> Promise<T> reject() {
return reject(new RuntimeException("Promise reject error"));
}
public static <T> Promise<T> reject(Exception err) {
return new Promise<>((resolve, reject) -> reject.accept(err));
}
public static <T, R> Function<T, Promise<R>> resolveFun(Function<T, R> function) {
return t -> new Promise<R>((resolve, reject) -> resolve.accept(function.apply(t)));
}
public <R> Promise<R> then(Function<T, Promise<R>> onFullFilled) {
switch (this.status) {
case RESOLVE:
return onFullFilled.apply(this.value);
case REJECT:
return new Promise<R>((resolve, reject) -> reject.accept(this.error));
default:
return new Promise<R>((resolve, reject) -> {
this.onFullFilled = t -> onFullFilled.apply(t).then(resolve, reject);
this.onRejected = reject;
});
}
}
public void then(Consumer<T> onFullFilled, Consumer<Exception> onRejected) {
switch (status) {
case RESOLVE:
if (onFullFilled != null) onFullFilled.accept(value);
break;
case REJECT:
if (onRejected != null) onRejected.accept(error);
break;
default:
if (onFullFilled != null) this.onFullFilled = onFullFilled;
if (onRejected != null) this.onRejected = onRejected;
break;
}
}
public void thenThrow(Consumer<T> onFullFilled) {
then(onFullFilled, e -> {
throw new RuntimeException(e.getMessage());
});
}
public T waitOrGet() throws Exception {
return waitOrGet(0);
}
public T waitOrGet(long timeout) throws Exception {
switch (status) {
case RESOLVE:
return value;
case REJECT:
throw error;
default:
synchronized (this) {
this.wait(timeout);
}
if (STATUS.PENDING.equals(status)) {
throw new RuntimeException();
}
return waitOrGet(timeout);
}
}
public interface Fun<T> {
void call(Consumer<T> resolve, Consumer<Exception> reject);
}
}
package com.gx.obe.bind.prop;
import java.util.Arrays;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.gx.obe.bind.view.View;
import com.gx.obe.bind.view.Write;
public class Comp<T> extends Prop<T> {
public Comp(Supplier<T> supplier, String name, View... properties) {
super(Objects.requireNonNull(supplier).get());
Arrays.stream(Objects.requireNonNull(properties)).forEach(p -> p.addChangeListener(() -> set(supplier.get())));
}
@Override
public Comp<T> as(String name) {
super.as(name);
return this;
}
@Override
public void bind(Write<T> write) {
super.bind(write);
}
public Comp<T> addSet(Consumer<T> consumer) {
super.addChangeListener(() -> consumer.accept(get()));
return this;
}
}
package com.gx.obe.bind.prop;
import java.util.Objects;
import java.util.UUID;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import com.gx.obe.bind.base.P;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.MView;
import com.gx.obe.bind.view.Read;
import com.gx.obe.bind.view.View;
import com.gx.obe.bind.view.Write;
public class Prop<T> extends P<T> implements MView<T> {
private Lock lock = new Lock();
public Prop() {}
public Prop(T value) {
set(value);
}
public Prop<T> orElseGet(Supplier<T> other) {
super.orElseGet(other);
return this;
}
public Prop<T> orElse(T defaultValue) {
super.orElse(defaultValue);
return this;
}
@Override
public Prop<T> as(String name) {
super.as(name);
return this;
}
@Override
public Prop<T> limit(BiPredicate<T, T> predicate) {
super.limit(predicate);
return this;
}
public boolean isLock() {
return lock.isLock();
}
public void replace(Function<T, T> function) {
set(Objects.requireNonNull(function).apply(get()));
}
public void changer(Consumer<T> consumer) {
Objects.requireNonNull(consumer).accept(get());
set(get());
}
public void bindBidirectional(MView<T> mView) {
Objects.requireNonNull(mView);
String key = UUID.randomUUID().toString();
bind(key, mView);
mView.addChangeListener(() -> set(mView.get(), key));
}
public void bindBidirectional(Write<T> write, Read<T> read, View model) {
Objects.requireNonNull(write);
Objects.requireNonNull(read);
Objects.requireNonNull(model);
String key = UUID.randomUUID().toString();
bind(key, write);
model.addChangeListener(() -> set(read.get(), key));
}
@Override
public void set(T value) {
lock.sync(() -> change(value));
}
private void set(T value, String key) {
lock.sync(() -> change(value, key));
}
}
class Lock {
private boolean lock = false;
public boolean isLock() {
return lock;
}
public void sync(ChangeListener changeListener) {
if (lock) return;
lock = true;
changeListener.change();
lock = false;
}
}
package com.gx.obe.bind.prop;
import java.util.Objects;
import java.util.function.BiPredicate;
import com.gx.obe.bind.base.P;
import com.gx.obe.bind.view.RView;
import com.gx.obe.bind.view.Read;
import com.gx.obe.bind.view.View;
public class RProp<T> extends P<T> {
public void reader(Read<? extends T> read, View model) {
Objects.requireNonNull(read);
Objects.requireNonNull(model);
model.addChangeListener(() -> change(read.get()));
}
public void reader(RView<? extends T> rView) {
reader(rView, rView);
}
public RProp<T> as(String name) {
super.as(name);
return this;
}
public RProp<T> limit(BiPredicate<T, T> predicate) {
super.limit(predicate);
return this;
}
}
package com.gx.obe.bind.recursion;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
public interface RStream<T> {
void forEach(Consumer<T> action);
void forEach(TreeForEach<T> treeForEach);
void forEach(BiConsumer<List<Integer>, T> indexConsumer);
Optional<T> findAny(Predicate<T> predicate);
List<T> filter(Predicate<T> predicate);
}
package com.gx.obe.bind.recursion;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class Recursions<T> {
private Function<T, Stream<T>> toStreamFun;
public static <T> Recursions<T> array(Function<T, T[]> toArrayFun) {
return new Recursions<>(toArrayFun.andThen(t -> Optional.ofNullable(t).map(Stream::of).orElse(null)));
}
public static <T> Recursions<T> list(Function<T, List<T>> toListFun) {
return new Recursions<>(toListFun.andThen(t -> Optional.ofNullable(t).map(List::stream).orElse(null)));
}
public static <T> Recursions<T> stream(Function<T, Stream<T>> toStreamFun) {
return new Recursions<>(toStreamFun);
}
public Recursions(Function<T, Stream<T>> toStreamFun) {
this.toStreamFun = toStreamFun;
}
public RStream<T> toStream(T obj) {
return toStream(Stream.of(obj));
}
public RStream<T> toStream(T[] array) {
return toStream(Stream.of(array));
}
public RStream<T> toStream(List<T> stream) {
return toStream(stream.stream());
}
public RStream<T> toStream(Stream<T> stream) {
return new RStream<T>() {
public void forEach(Consumer<T> action) {
new ForEachRecursion(action).exe(stream);
}
public void forEach(TreeForEach<T> treeForEach) {
new TreeForEachRecursion(treeForEach).exe(stream);
}
public void forEach(BiConsumer<List<Integer>, T> indexConsumer) {
new IndexForEachRecursion(indexConsumer).exe(stream);
}
public Optional<T> findAny(Predicate<T> predicate) {
Data data = new Data();
new AnyMatchRecursion(t -> {
boolean test = predicate.test(t);
if (test) data.t = t;
return test;
}).exe(stream);
return Optional.ofNullable(data.t);
}
public List<T> filter(Predicate<T> predicate) {
List<T> list = new ArrayList<>();
new ForEachRecursion(t -> {
if (predicate.test(t)) list.add(t);
}).exe(stream);
return list;
}
};
}
private class AnyMatchRecursion {
private Predicate<T> predicate;
public AnyMatchRecursion(Predicate<T> predicate) {
this.predicate = predicate;
}
private boolean exe(Stream<T> stream) {
return stream.anyMatch(t -> {
if (predicate.test(t)) return true;
return Optional.ofNullable(t).map(toStreamFun).map(this::exe).orElse(false);
});
}
}
private class ForEachRecursion {
private Consumer<T> consumer;
public ForEachRecursion(Consumer<T> consumer) {
this.consumer = consumer;
}
private void exe(Stream<T> stream) {
stream.forEach(t -> {
consumer.accept(t);
Optional.ofNullable(t).map(toStreamFun).ifPresent(this::exe);
});
}
}
private class TreeForEachRecursion {
private TreeForEach<T> treeForEach;
public TreeForEachRecursion(TreeForEach<T> treeForEach) {
this.treeForEach = treeForEach;
}
private void exe(Stream<T> stream) {
recursion(stream.iterator(), true);
}
private void recursion(Iterator<T> iterator, boolean root) {
iterator.forEachRemaining(t -> {
Iterator<T> citerator = Optional.of(t).map(toStreamFun).map(Stream::iterator).orElse(null);
boolean leaf = citerator == null || !citerator.hasNext();
treeForEach.action(root, leaf, t);
if (!leaf) recursion(citerator, false);
});
}
}
private class IndexForEachRecursion {
private BiConsumer<List<Integer>, T> indexConsumer;
public IndexForEachRecursion(BiConsumer<List<Integer>, T> indexConsumer) {
this.indexConsumer = indexConsumer;
}
private void exe(Stream<T> stream) {
recursion(stream, new ArrayList<>());
}
private void recursion(Stream<T> stream, List<Integer> pIndex) {
AtomicInteger i = new AtomicInteger(1);
stream.forEach(t -> {
List<Integer> index = new ArrayList<>(pIndex);
index.add(i.getAndIncrement());
indexConsumer.accept(index, t);
Optional.ofNullable(t).map(toStreamFun).ifPresent(s -> recursion(s, index));
});
}
}
private class Data {
private T t;
}
}
package com.gx.obe.bind.recursion;
public interface TreeForEach<T> {
void action(boolean root, boolean leaf, T t);
}
package com.gx.obe.bind.rx;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class RxBind<T> {
private Supplier<T> supplier = () -> null;
private Consumer<Runnable> supplierSync = Runnable::run;
private Consumer<Runnable> consumerSync = Runnable::run;
private Supplier<Boolean> check = () -> true;
private Supplier<T> other = () -> null;
private Tangent tangent = Tangent.TEMP;
public RxBind(Supplier<T> supplier) {
this.supplier = supplier;
}
public static <T> RxBind<T> run(Supplier<T> supplier) {
return new RxBind<T>(supplier);
}
public RxBind<T> tangent(Tangent tangent) {
this.tangent = tangent;
return this;
}
public RxBind<T> supplierSync(Consumer<Runnable> supplierSync) {
this.supplierSync = supplierSync;
return this;
}
public RxBind<T> consumerSync(Consumer<Runnable> consumerSync) {
this.consumerSync = consumerSync;
return this;
}
public RxBind<T> check(Supplier<Boolean> check) {
this.check = check;
return this;
}
public RxBind<T> other(Supplier<T> other) {
this.other = other;
return this;
}
public void exe(Consumer<T> consumer) {
supplierSync.accept(() -> {
Status<T> supplyStatus = supplyStatus();
consumerSync.accept(() -> {
if (check.get()) return;
if (supplyStatus.isErrer()) {
tangent.error(supplyStatus.getException());
} else {
tangent.after();
try {
consumer.accept(Optional.ofNullable(supplyStatus.getT()).orElseGet(other));
} catch (Exception e) {
e.printStackTrace();
}
}
});
});
tangent.before();
}
public Status<T> supplyStatus() {
Status<T> status = new Status<>();
try {
status.setT(supplier.get());
} catch (Exception e) {
status.setErrer(true);
status.setException(e);
}
return status;
}
}
package com.gx.obe.bind.rx;
public class Status<T> {
private Exception exception;
private T t;
private boolean errer;
public Exception getException() {
return exception;
}
public void setException(Exception exception) {
this.exception = exception;
}
public T getT() {
return t;
}
public void setT(T t) {
this.t = t;
}
public boolean isErrer() {
return errer;
}
public void setErrer(boolean errer) {
this.errer = errer;
}
}
package com.gx.obe.bind.rx;
public interface Tangent {
static Tangent TEMP = new Tangent() {
public void error(Exception e) {
e.printStackTrace();
}
public void before() {}
public void after() {}
};
void before();
void after();
void error(Exception e);
}
package com.gx.obe.bind.stream;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class MapStream<K, V> {
private Map<K, V> map;
public MapStream(Map<K, V> map) {
this.map = map;
}
public static <K, V> MapStream<K, V> of(Map<K, V> map) {
return new MapStream<>(map);
}
public <T> MapStream<K, T> valueMap(Function<V, T> function) {
Map<K, T> map = new HashMap<>();
this.map.forEach((k, v) -> map.put(k, function.apply(v)));
return MapStream.of(map);
}
public <T> void valueMap(Function<V, T> function, Map<K, T> map) {
this.map.forEach((k, v) -> map.put(k, function.apply(v)));
}
public MapStream<K, V> removeValueIsNull() {
Map<K, V> map = new HashMap<>();
this.map.forEach((k, v) -> {
if (v != null) map.put(k, v);
});
return MapStream.of(map);
}
public MapStream<K, V> removeValue(Predicate<V> predicate) {
Map<K, V> map = new HashMap<>();
this.map.forEach((k, v) -> {
if (!predicate.test(v)) map.put(k, v);
});
return MapStream.of(map);
}
public Stream<K> keyStream(Predicate<V> vPredicate) {
return map.entrySet().stream().filter(e -> vPredicate.test(e.getValue())).map(e -> e.getKey());
}
public Map<K, V> toMap() {
return map;
}
public void forEach(BiConsumer<K, V> action) {
map.forEach(action);
}
}
package com.gx.obe.bind.utils;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class CollectorUtils {
public static <T, K1, K2> Collector<T, ?, Map<K1, Map<K2, T>>> groupingToMap(Function<? super T, ? extends K1> classifier, Function<? super T, ? extends K2> keyMapper) {
return Collectors.groupingBy(classifier, Collectors.toMap(keyMapper, Function.identity()));
}
}
package com.gx.obe.bind.utils;
import java.util.function.Function;
import com.gx.obe.bind.prop.Prop;
public class PropUtils {
public static <T, R> void bindBidirectional(Prop<T> tProp, Prop<R> rProp, Function<T, R> trFunction, Function<R, T> rtFunction) {
tProp.addChangeListener(() -> {
if (rProp.isLock()) return;
rProp.set(trFunction.apply(tProp.get()));
});
rProp.addChangeListener(() -> {
if (tProp.isLock()) return;
tProp.set(rtFunction.apply(rProp.get()));
});
}
}
package com.gx.obe.bind.view;
public interface ChangeListener {
void change();
default ChangeListener andThen(ChangeListener changeListener) {
return () -> {
this.change();
changeListener.change();
};
}
static ChangeListener EMPTY = () -> {};
}
package com.gx.obe.bind.view;
public interface MView<T> extends RView<T>, Write<T> {}
package com.gx.obe.bind.view;
public interface RView<T> extends View, Read<T> {}
package com.gx.obe.bind.view;
@FunctionalInterface
public interface Read<T> {
T get();
}
package com.gx.obe.bind.view;
@FunctionalInterface
public interface View {
void addChangeListener(ChangeListener changeListener);
}
package com.gx.obe.bind.view;
@FunctionalInterface
public interface Write<T> {
void set(T t);
}
......@@ -536,6 +536,10 @@ public class ProgressMessageDialog extends Shell implements ProgressMessageListe
public boolean getFinishFlag() {
return finishFlag;
}
public int getErrorMessagesSize() {
return errorMessages;
}
}
......
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Component
Bundle-SymbolicName: com.gx.obe.component
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.gx.obe.component.Activator
Bundle-Vendor: GX
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.swt.core,
com.gx.obe.bind,
com.gx.obe.utils,
com.gx.obe.components.core
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.gx.obe.component
Bundle-ActivationPolicy: lazy
Export-Package: com.gx.obe.component.comparison,
com.gx.obe.component.form,
com.gx.obe.component.grid,
com.gx.obe.component.handler,
com.gx.obe.component.listener,
com.gx.obe.component.menu,
com.gx.obe.component.rx,
com.gx.obe.component.tabfolder,
com.gx.obe.component.table,
com.gx.obe.component.text,
com.gx.obe.component.tree,
com.gx.obe.component.utils,
com.gx.obe.component.verify
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
javacDefaultEncoding.. = UTF-8
\ No newline at end of file
package com.gx.obe.component;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.gx.obe.component"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
package com.gx.obe.component.comparison;
public class Column {
private String id;
private String name;
public Column(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}
package com.gx.obe.component.comparison;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.gx.obe.util.utils.Keys;
public class ComparisonData {
private List<Column> headColList = new ArrayList<>();
private List<Column> titleColList = new ArrayList<>();
private List<Column> itemColList = new ArrayList<>();
private List<String> rowList = new ArrayList<>();
private Map<Keys, String> headContentMap = new HashMap<>();
private Map<Keys, String> comparisonContentMap = new HashMap<>();
public boolean addHeadCol(Column col) {
return headColList.add(col);
}
public boolean addTitleCol(Column col) {
return titleColList.add(col);
}
public boolean addItemCol(Column col) {
return itemColList.add(col);
}
public boolean addRow(String row) {
return rowList.add(row);
}
public String putHeadContent(String rowId, String headId, String value) {
return headContentMap.put(Keys.of(rowId, headId), value);
}
public String putComparisonContent(String rowId, String titleId, String itemId, String value) {
return comparisonContentMap.put(Keys.of(rowId, titleId, itemId), value);
}
public List<Column> getHeadColList() {
return headColList;
}
public List<Column> getTitleColList() {
return titleColList;
}
public List<Column> getItemColList() {
return itemColList;
}
public List<String> getRowList() {
return rowList;
}
public Map<Keys, String> getHeadContentMap() {
return headContentMap;
}
public Map<Keys, String> getComparisonContentMap() {
return comparisonContentMap;
}
}
package com.gx.obe.component.comparison;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.IntStream;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.util.utils.Keys;
import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableCellRenderer;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.FixedWrapCellRenderer;
import de.kupzog.ktable.renderers.TextWrapCellRenderer;
public class ComparisonTable extends KTable {
/**
* @Description: 换行文本渲染
*/
private static final FixedWrapCellRenderer FIXED_RENDERER = new FixedWrapCellRenderer();
/**
* @Description: 换行文本渲染
*/
private static final TextWrapCellRenderer TEXT_RENDERER = new TextWrapCellRenderer();
/**
* @Description: 固定行数
*/
private static final int HEAD_ROW = 2;
private final CommonKtableCModel model;
private final List<Column> headColList;
private final List<Column> titleColList;
private final List<Column> itemColList;
private final List<String> rowList;
private final Map<Keys, String> headContentMap;
private final Map<Keys, String> comparisonContentMap;
public ComparisonTable(Composite parent, ComparisonData comparisonData) {
super(parent, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY | SWTX.FILL_WITH_LASTCOL);
comparisonData = Optional.ofNullable(comparisonData).orElseGet(ComparisonData::new);
this.headColList = comparisonData.getHeadColList();
this.titleColList = comparisonData.getTitleColList();
this.itemColList = comparisonData.getItemColList();
this.rowList = comparisonData.getRowList();
this.headContentMap = comparisonData.getHeadContentMap();
this.comparisonContentMap = comparisonData.getComparisonContentMap();
this.model = new CommonKtableCModel(this, HEAD_ROW, headColList.size(), this.rowList.size(), titleColList.size() * itemColList.size());
this.setModel(model);
IntStream.range(0, headColList.size()).forEach(i -> model.addRowSpan(0, i, HEAD_ROW));
IntStream.range(0, titleColList.size()).map(i -> i * itemColList.size()).map(i -> i + headColList.size()).forEach(i -> model.addColSpan(0, i, itemColList.size()));
IntStream.range(0, titleColList.size() * itemColList.size( )+ headColList.size()).forEach(i -> model.setColumnWidth(i, 100));
this.model.setRowHeightRender($ -> 30);
// this.model.setCellBackgroundRender(($, $$) -> SWTResourceManager.getColor(SWT.COLOR_WHITE));
this.model.setCellContentRender(this::receiveContent);
this.model.setCellRender(this::receiveCellRender);
this.model.setCellAlignmentRender(this::receiveCellAlignment);
}
/**
* @Description: 加载内容
* @author chenxw
* @param row
* @param col
* @return
*/
private String receiveContent(int row, int col) {
if (col < headColList.size()) {
if (row == 0) return Optional.of(headColList.get(col)).map(Column::getName).orElse("");
if (row == 1) return "";
return Optional.of(Keys.of(rowList.get(row - 2), headColList.get(col).getId())).map(headContentMap::get).orElse("");
}
col -= headColList.size();
int itemSize = itemColList.size();
if (row == 0) return Optional.of(titleColList.get(col / itemSize)).map(Column::getName).orElse("");
if (row == 1) return Optional.of(itemColList.get(col % itemSize)).map(Column::getName).orElse("");
try {
return Optional.of(Keys.of(rowList.get(row - 2), titleColList.get(col / itemSize).getId(), itemColList.get(col % itemSize).getId())).map(comparisonContentMap::get).orElse("");
} catch (Exception e) {
return "";
}
}
/**
* @Description: 加载渲染器
* @author chenxw
* @param row
* @param col
* @return
*/
private KTableCellRenderer receiveCellRender(int row, int col) {
if (this.model.isFixedCell(col, row)) {
return FIXED_RENDERER;
}
return TEXT_RENDERER;
}
/**
* @Description: 加载单元格对齐方式
* @author chenxw
* @param row
* @param col
* @return
*/
private int receiveCellAlignment(int row, int col) {
return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
}
}
package com.gx.obe.component.form;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
public class FForm<T> extends Composite {
private final IForm<T> iForm;
private final List<Consumer<T>> consumerList = new ArrayList<>();
private int numColumns;
public FForm(Composite parent, int numColumns) {
super(parent, SWT.NONE);
this.numColumns = numColumns;
setBackground(SWTResourceManager.getColor(215, 215, 215));
setBackgroundMode(SWT.INHERIT_FORCE);
GridLayout gridLayout = new GridLayout(numColumns * 2, false);
gridLayout.verticalSpacing = 1;
gridLayout.horizontalSpacing = 1;
gridLayout.marginHeight = 1;
gridLayout.marginWidth = 1;
setLayout(gridLayout);
iForm = new IForm<T>() {
@Override
public void addNull() {
CLabel lblNewLabel = new CLabel(FForm.this, SWT.RIGHT);
lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_lblNewLabel.heightHint = 30;
gd_lblNewLabel.widthHint = 100;
lblNewLabel.setLayoutData(gd_lblNewLabel);
CLabel lblNewLabel_1 = new CLabel(FForm.this, SWT.NONE);
lblNewLabel_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_lblNewLabel_1.heightHint = 30;
gd_lblNewLabel_1.widthHint = 200;
lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
}
public void add(String title, Function<T, String> getValueFun) {
CLabel lblNewLabel = new CLabel(FForm.this, SWT.RIGHT);
lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_lblNewLabel.heightHint = 30;
gd_lblNewLabel.widthHint = 100;
lblNewLabel.setLayoutData(gd_lblNewLabel);
lblNewLabel.setText(title);
CLabel lblNewLabel_1 = new CLabel(FForm.this, SWT.NONE);
lblNewLabel_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_lblNewLabel_1.heightHint = 30;
gd_lblNewLabel_1.widthHint = 200;
lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
consumerList.add(t -> lblNewLabel_1.setText(Optional.ofNullable(t).map(getValueFun).orElse("")));
}
public void addLong(String title, Function<T, String> getValueFun) {
CLabel lblNewLabel = new CLabel(FForm.this, SWT.RIGHT);
lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_lblNewLabel.heightHint = 30;
lblNewLabel.setLayoutData(gd_lblNewLabel);
lblNewLabel.setText(title);
CLabel lblNewLabel_1 = new CLabel(FForm.this, SWT.NONE);
lblNewLabel_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, numColumns * 2 - 1, 1);
gd_lblNewLabel_1.heightHint = 30;
lblNewLabel_1.setLayoutData(gd_lblNewLabel_1);
consumerList.add(t -> lblNewLabel_1.setText(Optional.ofNullable(t).map(getValueFun).orElse("")));
}
public void addBig(String title, Function<T, String> getValueFun, int height) {
CLabel lblNewLabel = new CLabel(FForm.this, SWT.RIGHT);
lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_lblNewLabel.heightHint = height;
lblNewLabel.setLayoutData(gd_lblNewLabel);
lblNewLabel.setText(title);
Composite composite = new Composite(FForm.this, SWT.NONE);
composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, false, numColumns * 2 - 1, 1);
gd_composite.heightHint = height;
composite.setLayoutData(gd_composite);
GridLayout gl_composite = new GridLayout(1, false);
gl_composite.marginWidth = 1;
composite.setLayout(gl_composite);
Text lblNewLabel_1 = new Text(composite, SWT.WRAP | SWT.V_SCROLL);
lblNewLabel_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
lblNewLabel_1.setEditable(false);
consumerList.add(t -> lblNewLabel_1.setText(Optional.ofNullable(t).map(getValueFun).orElse("")));
}
};
}
public void init(Consumer<IForm<T>> consumer) {
consumer.accept(iForm);
Composite composite_1 = new Composite(this, SWT.NONE);
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_lblNewLabel.heightHint = 0;
composite_1.setLayoutData(gd_lblNewLabel);
composite_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, numColumns * 2, 1));
}
public void refresh(T t) {
consumerList.forEach(c -> c.accept(t));
}
@Override
protected void checkSubclass() {}
}
package com.gx.obe.component.form;
import java.util.function.Function;
public interface IForm<T> {
void addNull();
void add(String title, Function<T, String> getValueFun);
void addLong(String title, Function<T, String> getValueFun);
void addBig(String title, Function<T, String> getValueFun, int height);
default void addBig(String title, Function<T, String> getValueFun) {
addBig(title, getValueFun, 95);
}
}
\ No newline at end of file
package com.gx.obe.component.grid;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.RView;
public class FGrid<T> extends Grid implements RView<T> {
private final List<Column<T>> columnList = new ArrayList<>();
private final List<ChangeListener> changeListeners = new ArrayList<>();
private T t;
@SuppressWarnings("unchecked")
public FGrid(Composite parent) {
super(parent, SWT.H_SCROLL | SWT.V_SCROLL);
this.setHeaderVisible(true);
this.setItemHeight(30);
this.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
GridItem gridItem = (GridItem) e.item;
t = (T) gridItem.getData();
changeListeners.forEach(ChangeListener::change);
}));
}
public GridColumn addIndexColumn(String name) {
columnList.add(new IndexColumn<>());
GridColumn gridColumn = new GridColumn(this, SWT.CENTER);
gridColumn.setText(name);
return gridColumn;
}
public GridColumn addColumn(String name, Function<T, String> function, int style) {
columnList.add(new Column<>(function));
GridColumn gridColumn = new GridColumn(this, style);
gridColumn.setText(name);
return gridColumn;
}
public void refresh(List<T> tList) {
this.removeAll();
if (tList != null) for (int i = 0; i < tList.size(); i++) {
T t = tList.get(i);
GridItem gridItem = new GridItem(this, SWT.NONE);
gridItem.setData(t);
for (int j = 0; j < columnList.size(); j++) {
Column<T> column = columnList.get(j);
if (column instanceof IndexColumn) {
gridItem.setText(j, i + 1 + "");
} else {
gridItem.setText(j, Optional.ofNullable(column.function.apply(t)).orElse(""));
}
}
}
}
private static class Column<T> {
private Function<T, String> function;
private Column(Function<T, String> function) {
this.function = function;
}
}
private static class IndexColumn<T> extends Column<T> {
private IndexColumn() {
super(null);
}
}
@Override
public void addChangeListener(ChangeListener changeListener) {
this.changeListeners.add(changeListener);
}
@Override
public T get() {
return t;
}
}
package com.gx.obe.component.handler;
import org.eclipse.swt.events.MouseListener;
public interface ISelection {
ISelection selection = new ISelection() {
public void setText(String text) {}
public void setSelection(boolean selection) {}
public void addMouseListener(MouseListener mouseUpAdapter) {}
};
void setText(String text);
void addMouseListener(MouseListener mouseUpAdapter);
void setSelection(boolean selection);
}
package com.gx.obe.component.handler;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.bind.prop.Prop;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.MView;
import com.gx.obe.component.utils.CompositeUtils;
public class RaidoHandler<T extends ISelection, R> implements MView<R> {
private ISelection tab = ISelection.selection;
private Composite composite;
private Function<Composite, T> iSelectionFunction;
private Prop<R> prop = new Prop<>();
private Map<R, T> map = new HashMap<>();
public RaidoHandler(Composite composite, Function<Composite, T> iSelectionFunction) {
this.composite = composite;
this.iSelectionFunction = iSelectionFunction;
}
public RaidoHandler<T, R> start() {
CompositeUtils.disposeChildren(composite);
return this;
}
public RaidoHandler<T, R> hand(R r, String text) {
return hand(r, t -> t.setText(text));
}
public RaidoHandler<T, R> hand(R r, Consumer<T> setConsumer) {
T t = iSelectionFunction.apply(composite);
setConsumer.accept(t);
t.addMouseListener(MouseListener.mouseUpAdapter($ -> prop.set(r)));
map.put(r, t);
return this;
}
public void end() {
prop.bind(r -> {
tab.setSelection(false);
tab = map.get(r);
tab.setSelection(true);
});
composite.layout();
composite.getParent().layout();
}
@Override
public void addChangeListener(ChangeListener changeListener) {
prop.addChangeListener(changeListener);
}
@Override
public R get() {
return prop.get();
}
@Override
public void set(R r) {
prop.set(r);
}
}
package com.gx.obe.component.handler;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.bind.call.Callback;
import com.gx.obe.component.utils.CompositeUtils;
public class TabHandler<T extends ISelection> {
private ISelection tab;
private final Composite composite;
private final Function<Composite, T> iTabFunction;
private Callback firstCall;
public TabHandler(Composite composite, Function<Composite, T> iTabFunction) {
this.composite = composite;
this.iTabFunction = iTabFunction;
}
public TabHandler<T> start() {
CompositeUtils.disposeChildren(composite);
firstCall = null;
return this;
}
public <R> TabHandler<T> hand(String text, Callback callback) {
return hand(null, (t, r) -> t.setText(text), r -> callback.call());
}
public <R> TabHandler<T> hand(Consumer<T> setConsumer, Callback callback) {
return hand(null, (t, r) -> setConsumer.accept(t), r -> callback.call());
}
public <R> TabHandler<T> hand(R r, BiConsumer<T, R> setBiConsumer, Consumer<R> consumer) {
T t = iTabFunction.apply(composite);
setBiConsumer.accept(t, r);
t.addMouseListener(MouseListener.mouseUpAdapter($ -> {
tab.setSelection(false);
tab = t;
tab.setSelection(true);
consumer.accept(r);
}));
if (firstCall == null) firstCall = () -> consumer.accept(r);
return this;
}
public void end() {
composite.layout();
composite.getParent().layout();
CompositeUtils.getFirst(composite).ifPresent(t -> {
tab = (ISelection) t;
tab.setSelection(true);
firstCall.call();
});
}
public <R> TabHandler<T> listHand(List<R> tList, Function<R, String> getTestFunction, Consumer<R> consumer) {
return listHand(tList, (t, r) -> t.setText(getTestFunction.apply(r)), consumer);
}
public <R> TabHandler<T> listHand(List<R> tList, BiConsumer<T, R> setBiConsumer, Consumer<R> consumer) {
if (tList != null) tList.forEach(r -> hand(r, setBiConsumer, consumer));
return this;
}
}
package com.gx.obe.component.listener;
public interface SelectionListener<T> {
void selection(T t);
}
package com.gx.obe.component.menu;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;
import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Widget;
import com.gx.obe.bind.fun.Fun;
import com.gx.obe.bind.prop.Prop;
import com.gx.obe.util.utils.PredicateUtils;
public class ListMenu<T> extends Composite {
protected Consumer<T> consumer = t -> {};
private Prop<List<T>> tListProp = new Prop<>(new ArrayList<>());
private Prop<Integer> menuWidth = new Prop<>(300);
/**
* @author chenxw
* @param parent
* @param style
*/
public ListMenu(Composite parent, Function<T, String> menuNameFun, Function<Composite, Consumer<T>> function) {
super(parent, SWT.NONE);
setLayout(new GridLayout(2, false));
Composite menuComposite = new Composite(this, SWT.NONE);
menuComposite.setLayout(new GridLayout(1, false));
menuComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
Grid grid = new Grid(menuComposite, SWT.V_SCROLL);
grid.addSelectionListener(SelectionListener.widgetSelectedAdapter(this::widgetSelected));
grid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
tListProp.bind(l -> {
grid.removeAll();
l.stream().forEach(t -> {
GridItem gridItem = new GridItem(grid, SWT.NONE);
gridItem.setText(menuNameFun.apply(t));
gridItem.setData(t);
gridItem.setHeight(30);
});
Optional.of(grid).filter(Fun.of(Grid::getItemCount).toTest(PredicateUtils.higher(0))).ifPresent(g -> g.select(0));
Optional.of(grid).map(Grid::getSelection).map(Stream::of).flatMap(Stream::findFirst).ifPresent(this::selectItemAction);
});
GridColumn gridColumn = new GridColumn(grid, SWT.NONE);
menuWidth.bind(gridColumn::setWidth);
Composite content = new Composite(this, SWT.NONE);
content.setLayout(new FillLayout(SWT.HORIZONTAL));
content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
consumer = Optional.ofNullable(function).orElseGet(() -> p -> t -> {}).apply(content);
}
public void refresh(List<T> tList) {
tListProp.set(tList);
}
public void setMenuWidth(int menuWidth) {
this.menuWidth.set(menuWidth);
}
private void widgetSelected(SelectionEvent e) {
selectItemAction(e.item);
}
private void selectItemAction(Widget item) {
@SuppressWarnings("unchecked")
T t = (T) item.getData();
consumer.accept(t);
}
@Override
protected void checkSubclass() {}
}
package com.gx.obe.component.rx;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Widget;
import com.gx.obe.bind.promise.Promise;
import com.gx.obe.bind.rx.RxBind;
import com.gx.obe.bind.rx.Tangent;
public class RxSwt<T> {
private final RxBind<T> rxBind;
private Tangent tangent = Tangent.TEMP;
private Supplier<Boolean> check = () -> false;
private Supplier<T> other = () -> null;
public static <T> RxSwt<T> run(Supplier<T> run) {
return new RxSwt<T>(run);
}
public RxSwt<T> setTangent(Tangent tangent) {
this.tangent = tangent;
return this;
}
private RxSwt(Supplier<T> run) {
rxBind = RxBind.run(run);
}
public RxSwt<T> checkWidget(Widget widget) {
if (widget != null) {
this.check = widget::isDisposed;
}
return this;
}
public RxSwt<T> other(Supplier<T> other) {
this.other = other;
return this;
}
public Promise<T> exe() {
return new Promise<>((s, f) -> exe(s));
}
public void exe(Consumer<T> consumer) {
rxBind.supplierSync(this::startThead).consumerSync(Display.getDefault()::asyncExec).tangent(tangent).check(check).other(other).exe(consumer);
}
private void startThead(Runnable runnable) {
new Thread(runnable).start();
}
}
package com.gx.obe.component.tabfolder;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.core.widgets.ImageButton;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.ColorConstants;
import com.gx.obe.bind.call.Callback;
import com.gx.obe.bind.prop.Prop;
import com.gx.obe.component.utils.CompositeUtils;
import com.swtdesigner.SWTResourceManager;
/**
* @Description: 选项卡布局
* @author chenxw
*/
public abstract class CTabFolder extends Composite {
private final StackLayout stackLayout = new StackLayout();
private final Composite itemComposite;
private final Composite contentComposite;
private CTabItem curTabItem;
private Composite actionComposite;
private int index;
/**
* @author chenxw
* @param parent
* @param style
*/
public CTabFolder(Composite parent, int style) {
super(parent, style);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
setLayout(gridLayout);
Prop<Boolean> showItemList = new Prop<Boolean>(false);
itemComposite = new Composite(this, SWT.NONE);
RowLayout rl_composite = new RowLayout(SWT.HORIZONTAL);
rl_composite.marginBottom = 0;
rl_composite.marginTop = 0;
rl_composite.marginRight = 0;
rl_composite.marginLeft = 0;
itemComposite.setLayout(rl_composite);
itemComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
showItemList.bind(t -> WidgetUtils.setControlVisible(itemComposite, t));
ESepator timeSep = new ESepator(this, SWT.HORIZONTAL);
timeSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
timeSep.setBackground(ColorConstants.SKIN_BG);
timeSep.setLineWidth(3);
showItemList.bind(t -> WidgetUtils.setControlVisible(timeSep, t));
showItemList.bind(t -> layout());
contentComposite = new Composite(this, SWT.NONE);
contentComposite.setLayout(stackLayout);
contentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
actionComposite = new Composite(contentComposite, SWT.NONE);
actionComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
init();
showItemList.set(itemComposite.getChildren().length > 1);
}
public void notifyMouseUp() {
CompositeUtils.notifyMouseUp(itemComposite);
}
public void refresh() {
if (curTabItem != null) curTabItem.refresh();
else CompositeUtils.notifyMouseUp(itemComposite);
}
/**
* @Description: 初始化
* @author chenxw
*/
protected abstract void init();
/**
* @Description: 选项卡
* @author chenxw
*/
protected class CTabItem extends ImageButton {
private Consumer<Composite> consumer = t -> {};
private Callback callback = () -> {};
private boolean action;
private boolean refresh;
private int index = 0;
/**
* @author chenxw
* @param text
* @param function
*/
public CTabItem(String text) {
super(itemComposite, SWT.NONE);
this.setBorderColor(null);
this.setForeground(SWTResourceManager.getColor(127, 127, 127));
this.setBackgroundColor(SWTResourceManager.getColor(221, 221, 221));
this.setActiveForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
this.setActiveBgColor(SWTResourceManager.getColor(255, 153, 0));
this.setSelectionForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
this.setSelectionBgColor(SWTResourceManager.getColor(60, 138, 226));
this.setLeftMargin(15);
this.setRightMargin(15);
this.setTopMargin(6);
this.setBottomMargin(6);
setText(text);
setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD));
addMouseListener(MouseListener.mouseUpAdapter(this::mouseUpAction));
}
public void action(Consumer<Composite> consumer) {
this.consumer = Objects.requireNonNull(consumer);
this.action = true;
}
public void refresh(Function<Composite, Callback> function) {
this.callback = Objects.requireNonNull(function).apply(contentComposite);
this.refresh = true;
this.index = ++CTabFolder.this.index;
}
/**
* @Description: 鼠标点击事件
* @author chenxw
* @param e
*/
private void mouseUpAction(MouseEvent e) {
Optional.ofNullable(curTabItem).ifPresent(t -> t.setSelection(false));
this.setSelection(true);
curTabItem = this;
if (action) stackLayout.topControl = actionComposite;
if (refresh) stackLayout.topControl = contentComposite.getChildren()[index];
contentComposite.layout();
refresh();
}
private void refresh() {
if (action) {
CompositeUtils.disposeChildren(actionComposite);
consumer.accept(actionComposite);
actionComposite.layout();
}
if (refresh) callback.call();
}
}
}
package com.gx.obe.component.tabfolder;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.RView;
/**
* @Description: 选项卡布局
* @author chenxw
* @param <T>
*/
public abstract class FTabFolder<T> extends CTabFolder implements RView<T> {
private ChangeListener changeListener;
private RView<T> rView;
/**
* @author chenxw
* @param parent
* @param style
*/
public FTabFolder(Composite parent, int style) {
super(parent, style);
}
@Override
public void addChangeListener(ChangeListener changeListener) {
this.changeListener = Objects.requireNonNull(changeListener);
notifyMouseUp();
}
@Override
public T get() {
return Optional.ofNullable(rView).map(RView::get).orElse(null);
}
/**
* @Description: 选项卡
* @author chenxw
*/
protected class FTabItem extends CTabFolder.CTabItem {
/**
* @author chenxw
* @param text
* @param function
*/
public FTabItem(String text) {
super(text);
}
/**
* @Description:
* @author chenxw
* @param function
*/
public void action(Function<Composite, RView<T>> function) {
super.action(t -> {
rView = function.apply(t);
rView.addChangeListener(changeListener);
changeListener.change();
});
}
}
}
package com.gx.obe.component.table;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import com.swtdesigner.SWTResourceManager;
import de.kupzog.ktable.KTable;
import de.kupzog.ktable.KTableCellRenderer;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.editors.KTableCellEditorLink;
import de.kupzog.ktable.editors.KTableCellEditorText;
import de.kupzog.ktable.model.CommonKtableCModel;
import de.kupzog.ktable.renderers.FixedWrapCellRenderer;
import de.kupzog.ktable.renderers.LinkCellRenderer;
import de.kupzog.ktable.renderers.TextWrapCellRenderer;
public class CTable<T> extends KTable {
/**
* @Description: 换行文本渲染
*/
private static final FixedWrapCellRenderer FIXED_RENDERER = new FixedWrapCellRenderer();
/**
* @Description: 换行文本渲染
*/
private static final TextWrapCellRenderer TEXT_RENDERER = new TextWrapCellRenderer();
/**
* @Description: 固定行数
*/
private static final int HEAD_ROW = 1;
/**
* @Description: 默认最小列宽
*/
private static int COLUMN_MIN_WIDTH = -1;
/**
* @Description: 默认最小列宽
*/
private static int COLUMN_WIDTH = -1;
/**
* @Description: 默认最大列宽
*/
private static int COLUMN_MAX_WIDTH = -1;
/**
* @Description: 默认列对齐方式
*/
private static int ALIGN_HORIZONTAL = SWTX.ALIGN_HORIZONTAL_CENTER;
/**
* @Description: 固定列
*/
private final List<Column> headColumnList;
/**
* @Description: 内容列
*/
private final List<Column> contentColumnList;
/**
* @Description: 显示数据
*/
private final List<T> tList;
/**
* @Description: 表格模型
*/
private final CommonKtableCModel commonKtableCModel;
public CTable(Composite parent, List<Column> headColumnList, List<Column> contentColumnList, List<T> tList) {
super(parent, SWTX.AUTO_SCROLL | SWT.FULL_SELECTION | SWTX.EDIT_ON_KEY | SWTX.FILL_WITH_LASTCOL);
this.headColumnList = headColumnList;
this.contentColumnList = contentColumnList;
this.tList = Optional.ofNullable(tList).orElseGet(ArrayList::new);
this.commonKtableCModel = new CommonKtableCModel(this, HEAD_ROW, headColumnList.size(), this.tList.size(), contentColumnList.size());
show();
}
/**
* @Description: 显示
* @author chenxw
*/
private void show() {
for (int col = 0; col < commonKtableCModel.getColCount(); col++) {
int minWidth;
int width;
int maxWidth;
if (col < headColumnList.size()) {
minWidth = getHeadColumn(col).getMinWidth();
width = getHeadColumn(col).getWidth();
maxWidth = getHeadColumn(col).getMaxWidth();
} else {
minWidth = Optional.of(getContentColumn(col)).map(Column::getMinWidth).orElse(COLUMN_MIN_WIDTH);
width = Optional.of(getContentColumn(col)).map(Column::getWidth).orElse(COLUMN_WIDTH);
maxWidth = Optional.of(getContentColumn(col)).map(Column::getMaxWidth).orElse(COLUMN_MAX_WIDTH);
}
commonKtableCModel.setColumnMinWidth(col, minWidth);
commonKtableCModel.setColumnWidth(col, width);
commonKtableCModel.setColumnMaxWidth(col, maxWidth);
}
commonKtableCModel.setRowHeightRender(row -> 30);
commonKtableCModel.setCellBackgroundRender((a, b) -> SWTResourceManager.getColor(SWT.COLOR_WHITE));
commonKtableCModel.setCellContentRender(this::receiveContent);
commonKtableCModel.setCellRender(this::receiveCellRender);
commonKtableCModel.setCellEditorRender(this::receiveCellEditor);
commonKtableCModel.setCellImageRender(this::receiveCellImage);
commonKtableCModel.setCellAlignmentRender(this::receiveCellAlignment);
commonKtableCModel.setCellEditContentRender(this::receiveContent);
this.setModel(commonKtableCModel);
}
/**
* @Description: 加载内容
* @author chenxw
* @param row
* @param col
* @return
*/
private String receiveContent(int row, int col) {
if (row < HEAD_ROW) {
if (col < headColumnList.size()) {
return getHeadColumn(col).getName();
}
return getContentColumn(col).getName();
}
if (col < headColumnList.size()) {
return getHeadColumn(col).getFunction().apply(row);
}
return Optional.ofNullable(getContentColumn(col).getFunction().apply(row)).orElse("");
}
/**
* @Description: 编辑单元格内容
* @author chenxw
* @param row
* @param col
* @param content
* @return
*/
private void receiveContent(int row, int col, Object content) {
if (commonKtableCModel.isFixedCell(col, row)) {
return;
}
Column contentColumn = getContentColumn(col);
if (!(contentColumn instanceof Text)) {
return;
}
@SuppressWarnings("unchecked")
Text<T> textContentColumn = (Text<T>) contentColumn;
textContentColumn.action(getT(row), content);
redraw();
}
/**
* @Description: 加载渲染器
* @author chenxw
* @param row
* @param col
* @return
*/
private KTableCellRenderer receiveCellRender(int row, int col) {
if (commonKtableCModel.isFixedCell(col, row)) {
return FIXED_RENDERER;
}
Column contentColumn = getContentColumn(col);
if (!(contentColumn instanceof Link)) {
return TEXT_RENDERER;
}
@SuppressWarnings("unchecked")
Link<T> linkContentColumn = (Link<T>) contentColumn;
LinkCellRenderer linkCellRenderer = new LinkCellRenderer();
linkCellRenderer.setEnable(linkContentColumn.enable(getT(row)));
return linkCellRenderer;
}
/**
* @Description: 加载编辑器
* @author chenxw
* @param row
* @param col
* @return
*/
private Object receiveCellEditor(int row, int col) {
if (commonKtableCModel.isFixedCell(col, row)) {
return null;
}
Column contentColumn = getContentColumn(col);
if (contentColumn instanceof Link) {
return new KTableCellEditorLink(this, this::receiveAction);
} else if (contentColumn instanceof Text) {
@SuppressWarnings("unchecked")
Text<T> textContentColumn = (Text<T>) contentColumn;
KTableCellEditorText cellEditorText = new KTableCellEditorText();
cellEditorText.setTextLimit(textContentColumn.getTextLimit());
return cellEditorText;
}
return null;
}
/**
* @Description: 按钮点击事件
* @author chenxw
* @param row
* @param col
*/
private void receiveAction(int row, int col) {
if (commonKtableCModel.isFixedCell(col, row)) {
return;
}
Column contentColumn = getContentColumn(col);
if (!(contentColumn instanceof Link)) {
return;
}
@SuppressWarnings("unchecked")
Link<T> linkContentColumn = (Link<T>) contentColumn;
linkContentColumn.action(getT(row));
}
/**
* @Description: 加载图片
* @author chenxw
* @param row
* @param col
* @return
*/
private Image receiveCellImage(int row, int col) {
if (row < HEAD_ROW) {
return null;
}
if (col < headColumnList.size()) {
return getHeadColumn(col).getImage();
}
return getContentColumn(col).getImage();
}
/**
* @Description: 加载单元格对齐方式
* @author chenxw
* @param row
* @param col
* @return
*/
private int receiveCellAlignment(int row, int col) {
if (row < HEAD_ROW) {
return SWTX.ALIGN_VERTICAL_CENTER | SWTX.ALIGN_HORIZONTAL_CENTER;
}
int align;
if (col < headColumnList.size()) {
align = Optional.of(getHeadColumn(col)).map(Column::getAlign).orElse(ALIGN_HORIZONTAL);
} else {
align = Optional.of(getContentColumn(col)).map(Column::getAlign).orElse(ALIGN_HORIZONTAL);
}
return SWTX.ALIGN_VERTICAL_CENTER | align;
}
/**
* @Description: 获取固定列
* @author chenxw
* @param col
* @return
*/
private Column getHeadColumn(int col) {
return headColumnList.get(col);
}
/**
* @Description: 获取内容列
* @author chenxw
* @param col
* @return
*/
private Column getContentColumn(int col) {
return contentColumnList.get(col - headColumnList.size());
}
/**
* @Description: 获取T
* @author chenxw
* @param row
* @return
*/
public T getT(int row) {
row -= HEAD_ROW;
if (tList.size() > row) {
return tList.get(row);
}
return null;
}
}
package com.gx.obe.component.table;
import java.util.function.Function;
import org.eclipse.swt.graphics.Image;
import de.kupzog.ktable.SWTX;
/**
* @Description: 列
* @author chenxw
*/
public class Column {
public static final int ALIGN_LEFT = SWTX.ALIGN_HORIZONTAL_LEFT;
public static final int ALIGN_CENTER = SWTX.ALIGN_HORIZONTAL_CENTER;
public static final int ALIGN_RIGHT = SWTX.ALIGN_HORIZONTAL_RIGHT;
/**
* @Description: 名称
*/
private String name;
/**
* @Description: 根据序号获取展示内容
*/
private Function<Integer, String> function;
/**
* @Description: 图片
*/
private Image image;
/**
* @Description: 对齐方式
*/
private Integer align;
/**
* @Description: 最小列宽
*/
private Integer minWidth;
/**
* @Description: 列宽
*/
private Integer width;
/**
* @Description: 最大列宽
*/
private Integer maxWidth;
/**
* @author chenxw
* @param name
* @param function
*/
public Column(String name, Function<Integer, String> function) {
this.name = name;
this.function = function;
}
public String getName() {
return name;
}
public Function<Integer, String> getFunction() {
return function;
}
public Column image(Image image) {
this.image = image;
return this;
}
public Image getImage() {
return image;
}
public Column align(int align) {
this.align = align;
return this;
}
public Integer getAlign() {
return align;
}
public Column minWidth(int minWidth) {
this.minWidth = minWidth;
return this;
}
public Integer getMinWidth() {
return minWidth;
}
public Column width(int width) {
this.width = width;
return this;
}
public Integer getWidth() {
return width;
}
public Column maxWidth(int maxWidth) {
this.maxWidth = maxWidth;
return this;
}
public Integer getMaxWidth() {
return maxWidth;
}
}
\ No newline at end of file
package com.gx.obe.component.table;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import com.gx.obe.component.listener.SelectionListener;
import com.gx.obe.component.utils.CompositeUtils;
import de.kupzog.ktable.KTableCellSelectionAdapter;
/**
* @Description: 函数式表格
* @author chenxw
* @param <T>
*/
public abstract class FTable<T> extends Composite {
/**
* @Description:
*/
private CTable<T> cTable;
/**
* @Description: 获取t函数
*/
private final Function<Integer, T> tFun = this::getT;
/**
* @Description: 固定列
*/
private final List<Column> headColumnList = new ArrayList<>();
/**
* @Description: 内容列
*/
private final List<Column> contentColumnList = new ArrayList<>();
private List<SelectionListener<T>> selectionListenerList = new ArrayList<>();
/**
* @author chenxw
* @param parent
* @param tList
*/
public FTable(Composite parent, int style) {
super(parent, style);
setLayout(new FillLayout(SWT.HORIZONTAL));
init();
}
/**
* @Description: 初始化
* @author chenxw
*/
protected abstract void init();
/**
* @Description: 刷新
* @author chenxw
* @param tList
*/
public void refresh(List<T> tList) {
CompositeUtils.disposeChildren(this);
this.cTable = new CTable<>(this, headColumnList, contentColumnList, tList);
cTable.addCellSelectionListener(new KTableCellSelectionAdapter() {
public void cellSelected(int col, int row, int statemask) {
selection(row);
}
});
this.layout();
this.getParent().layout();
selection(1);
}
private void selection(int row) {
T t = getT(row);
if (t != null) selectionListenerList.forEach(l -> l.selection(t));
}
public void addSelectionListener(SelectionListener<T> selectionListener) {
this.selectionListenerList.add(selectionListener);
}
/**
* @Description: 获取T
* @author chenxw
* @param row
* @return
*/
private T getT(int row) {
return this.cTable.getT(row);
}
/**
* @Description: 索引列
* @author chenxw
*/
protected class IndexColumn extends Column {
public IndexColumn(String name) {
this(name, 50, String::valueOf);
}
public IndexColumn(String name, int width, Function<Integer, String> function) {
super(name, function);
headColumnList.add(this);
width(width).minWidth(width).maxWidth(width);
}
}
/**
* @Description: 固定列
* @author chenxw
*/
protected class HeadColumn extends Column {
public HeadColumn(String name, int width, Function<T, String> function) {
super(name, tFun.andThen(function));
headColumnList.add(this);
width(width).minWidth(width).maxWidth(width);
}
}
/**
* @Description: 内容列
* @author chenxw
*/
protected class ContentColumn extends Column {
public ContentColumn(String name, Function<T, String> function) {
super(name, tFun.andThen(function));
contentColumnList.add(this);
}
}
/**
* @Description: 链接内容列
* @author chenxw
*/
protected class LinkContentColumn extends ContentColumn implements Link<T> {
private Consumer<T> consumer;
private Predicate<T> predicate = t -> true;
public LinkContentColumn(String name, String content, Image image, Consumer<T> consumer) {
super(name, t -> content);
image(image);
this.consumer = consumer;
}
public void enable(Predicate<T> predicate) {
this.predicate = Objects.requireNonNull(predicate);
}
@Override
public boolean enable(T t) {
return predicate.test(t);
}
@Override
public void action(T t) {
consumer.accept(t);
}
}
/**
* @Description: 文本编辑内容列
* @author chenxw
*/
protected class TextContentColumn<R> extends ContentColumn implements Text<T> {
private Function<Object, R> format;
private BiConsumer<T, R> biConsumer;
private int textLimit = 1000;
public TextContentColumn(String name, Function<T, String> function, Function<Object, R> format, BiConsumer<T, R> biConsumer) {
super(name, function);
this.format = format;
this.biConsumer = biConsumer;
}
public void limit(int textLimit) {
this.textLimit = textLimit;
}
@Override
public void action(T t, Object content) {
biConsumer.accept(t, format.apply(content));
}
@Override
public int getTextLimit() {
return textLimit;
}
}
}
package com.gx.obe.component.table;
/**
* @Description: 链接
* @author chenxw
* @param <T>
*/
interface Link<T> {
boolean enable(T t);
void action(T t);
}
\ No newline at end of file
package com.gx.obe.component.table;
public interface Text<T> {
void action(T t, Object content);
int getTextLimit();
}
package com.gx.obe.component.text;
import java.math.BigDecimal;
import java.util.Objects;
import java.util.Optional;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import com.gx.obe.bind.fun.Fun;
import com.gx.obe.bind.prop.Prop;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.MView;
import com.gx.obe.components.core.util.MoneyUtils;
import com.swtdesigner.SWTResourceManager;
/**
* @Description: 大写金额文本框
* @author chenxw
*/
public class CapitalMoneyText extends Composite implements MView<BigDecimal> {
private final Prop<BigDecimal> moneyProp = new Prop<>(BigDecimal.ZERO);
private final Prop<Color> moneyColorProp = new Prop<>(SWTResourceManager.getColor(90, 147, 52));
private final Prop<Boolean> editableProp = new Prop<>(true);
public CapitalMoneyText(Composite parent, String unit) {
super(parent, SWT.NONE);
setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
setBackgroundMode(SWT.INHERIT_FORCE);
Objects.requireNonNull(unit);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
setLayout(gridLayout);
Composite composite = new Composite(this, SWT.NONE);
composite.setBackground(SWTResourceManager.getColor(238, 238, 238));
GridLayout gl_composite = new GridLayout(3, false);
gl_composite.marginHeight = 6;
gl_composite.marginWidth = 20;
gl_composite.horizontalSpacing = 20;
composite.setLayout(gl_composite);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setForeground(SWTResourceManager.getColor(188, 188, 188));
lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("小写");
MoneyText text = new MoneyText(composite, SWT.RIGHT, unit);
text.setFont(SWTResourceManager.getFont("微软雅黑", 18, SWT.NORMAL));
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
moneyProp.bindBidirectional(text);
moneyColorProp.bind(text::setForeground);
editableProp.bind(text::setEditable);
Label lblNewLabel_2 = new Label(composite, SWT.NONE);
lblNewLabel_2.setForeground(SWTResourceManager.getColor(160, 160, 160));
lblNewLabel_2.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
lblNewLabel_2.setText(unit);
Composite composite_1 = new Composite(this, SWT.NONE);
composite_1.setBackground(SWTResourceManager.getColor(245, 245, 245));
GridLayout gl_composite_1 = new GridLayout(2, false);
gl_composite_1.marginHeight = 6;
gl_composite_1.marginWidth = 20;
gl_composite_1.horizontalSpacing = 20;
composite_1.setLayout(gl_composite_1);
GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_composite_1.heightHint = 41;
composite_1.setLayoutData(gd_composite_1);
Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
lblNewLabel_1.setForeground(SWTResourceManager.getColor(188, 188, 188));
lblNewLabel_1.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.NORMAL));
lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, true, 1, 1));
lblNewLabel_1.setText("大写");
Text text_1 = new Text(composite_1, SWT.RIGHT);
text_1.setFont(SWTResourceManager.getFont("微软雅黑", 14, SWT.NORMAL));
text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
text_1.setEditable(false);
moneyProp.bind(Fun.of(this::moneyToCapital).toWrite(text_1::setText));
moneyColorProp.bind(text_1::setForeground);
}
/**
* @Description: 金额转大写
* @author chenxw
* @param money
* @return
*/
private String moneyToCapital(BigDecimal money) {
return Optional.ofNullable(money).map(BigDecimal::doubleValue).map(MoneyUtils::amountToChinese).orElse("");
}
@Override
public void addChangeListener(ChangeListener changeListener) {
moneyProp.addChangeListener(changeListener);
}
@Override
public void set(BigDecimal t) {
moneyProp.set(t);
}
/**
* @Description: 设置金额字体颜色
* @author chenxw
* @param moneyColor
*/
public void setMoneyColor(Color moneyColor) {
moneyColorProp.set(moneyColor);
}
/**
* @Description: 设置是否可编辑
* @author chenxw
* @param editable
*/
public void setEditable(Boolean editable) {
editableProp.set(editable);
}
@Override
public BigDecimal get() {
return moneyProp.get();
}
@Override
protected void checkSubclass() {}
}
\ No newline at end of file
package com.gx.obe.component.text;
import java.util.function.Supplier;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import com.gx.obe.ColorConstants;
import com.gx.obe.bind.prop.Prop;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.MView;
import com.gx.obe.component.verify.Verify;
import com.swtdesigner.SWTResourceManager;
/**
* @Description:
* @author chenxw
*/
public class DocumentText extends Composite implements MView<String>, Verify<String> {
/**
* @Description: 标题
*/
private final Prop<String> title = new Prop<>();
/**
* @Description: 内容
*/
private final Prop<String> content = new Prop<>();
/**
* @Description: 可编辑
*/
private final Prop<Boolean> editable = new Prop<>(false);
/**
* @Description: 获取内容文本框
*/
private Supplier<Control> contentTextGet;
/**
* @author chenxw
* @param parent
* @param style
*/
public DocumentText(Composite parent, int style) {
super(parent, style);
setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
setBackgroundMode(SWT.INHERIT_FORCE);
GridLayout gl_composite = new GridLayout(1, false);
gl_composite.marginHeight = 0;
gl_composite.marginWidth = 50;
setLayout(gl_composite);
Label titleLabel = new Label(this, SWT.NONE);
titleLabel.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
titleLabel.setForeground(ColorConstants.TITLE_FONT_COLOR);
titleLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
title.bind(titleLabel::setText);
StyledText contentText = new StyledText(this, SWT.WRAP | SWT.MULTI);
contentText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
contentText.setLineSpacing(10);
contentText.setIndent(30);
contentText.setFont(SWTResourceManager.getFont("微软雅黑", 12, SWT.NORMAL));
contentText.setForeground(ColorConstants.FONT_BLACK_COLOR);
editable.bind(contentText::setEditable);
content.bindBidirectional(contentText::setText, contentText::getText, t -> contentText.addModifyListener(e -> t.change()));
contentTextGet = () -> contentText;
Label memoTips = new Label(this, SWT.RIGHT);
memoTips.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
content.bind(t -> memoTips.setText("(" + t.length() + "/ " + "500)"));
}
/**
* @Description: 设置标题
* @author chenxw
* @param title
*/
public void setTitle(String title) {
this.title.set(title);
}
/**
* @Description: 设置可编辑状态
* @author chenxw
* @param editable
*/
public void setEditable(boolean editable) {
this.editable.set(editable);
}
@Override
public void addChangeListener(ChangeListener changeListener) {
content.addChangeListener(changeListener);
}
@Override
public String get() {
return content.get();
}
@Override
public void set(String content) {
this.content.set(content);
}
@Override
public Supplier<Control> getVerifyControl() {
return contentTextGet;
}
@Override
protected void checkSubclass() {}
}
package com.gx.obe.component.text;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import com.swtdesigner.SWTResourceManager;
public class FStyledText extends StyledText {
private StringBuilder textBuilder = new StringBuilder();
private List<StyleRange> styleRangeList = new ArrayList<>();
public FStyledText(Composite parent) {
super(parent, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
this.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
}
public void clear() {
textBuilder.delete(0, textBuilder.length());
styleRangeList.clear();
}
public void refresh() {
setText(textBuilder.toString());
styleRangeList.forEach(this::setStyleRange);
}
public void add(String title, String content, Color contentForeground, int contentFontStyle) {
if (textBuilder.length() != 0) textBuilder.append(" ");
addItem(title, content, contentForeground, contentFontStyle);
textBuilder.append(title).append(content);
}
public void addWrap(String title, String content, Color contentForeground, int contentFontStyle) {
textBuilder.append("\r\n");
addItem(title, content, contentForeground, contentFontStyle);
textBuilder.append(title).append(content);
}
private void addItem(String title, String content, Color contentForeground, int contentFontStyle) {
StyleRange titleStyleRange = new StyleRange();
titleStyleRange.start = textBuilder.length();
titleStyleRange.length = title.length();
titleStyleRange.foreground = SWTResourceManager.getColor(SWT.COLOR_BLUE);
titleStyleRange.fontStyle = SWT.BOLD;
styleRangeList.add(titleStyleRange);
StyleRange contentStyleRange = new StyleRange();
contentStyleRange.start = textBuilder.length() + title.length();
contentStyleRange.length = content.length();
contentStyleRange.foreground = contentForeground;
contentStyleRange.fontStyle = contentFontStyle;
styleRangeList.add(contentStyleRange);
}
@Override
protected void checkSubclass() {}
}
package com.gx.obe.component.text;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.RView;
import com.gx.obe.component.verify.IntegerVerifyListener;
public class IntegerText extends Text implements RView<Integer> {
public IntegerText(Composite parent, int style) {
super(parent, style);
addVerifyListener(new IntegerVerifyListener(false));
}
@Override
public void addChangeListener(ChangeListener changeListener) {
addModifyListener(e -> changeListener.change());
}
@Override
public Integer get() {
String text = getText();
if (text.isEmpty()) return null;
return Integer.valueOf(text);
}
@Override
protected void checkSubclass() {}
}
package com.gx.obe.component.text;
import java.math.BigDecimal;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.MView;
import com.gx.obe.component.verify.MoneyVerifyListener;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.util.MoneyUtils;
/**
* @Description: 金额输入框
* @author chenxw
*/
public class MoneyText extends Text implements MView<BigDecimal> {
private final String unit;
/**
* @author chenxw
* @param parent
* @param style
* @param unit
*/
public MoneyText(Composite parent, int style, String unit) {
super(parent, style);
this.unit = unit;
addVerifyListener(new MoneyVerifyListener(false, CommonEnum.WAN_YUAN.equals(CommonEnum.getPriceUnitType(unit))));
}
@Override
public void set(BigDecimal t) {
setText(MoneyUtils.getMoneyFormatByUnit(t, unit));
}
@Override
public BigDecimal get() {
return MoneyUtils.getMoneyFromText(getText(), unit);
}
@Override
public void addChangeListener(ChangeListener changeListener) {
addModifyListener(e -> changeListener.change());
}
@Override
protected void checkSubclass() {}
}
\ No newline at end of file
package com.gx.obe.component.text;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.function.UnaryOperator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import com.gx.obe.bind.prop.RProp;
import com.gx.obe.bind.view.ChangeListener;
import com.gx.obe.bind.view.RView;
import com.swtdesigner.SWTResourceManager;
/**
* @Description: 小写金额文本框
* @author chenxw
*/
public class OrdinaryMoneyText extends Composite implements RView<UnaryOperator<BigDecimal>> {
/**
* @Description: 金额
*/
private RProp<BigDecimal> moneyProp = new RProp<BigDecimal>();
/**
* @author chenxw
* @param parent
* @param unit
*/
public OrdinaryMoneyText(Composite parent, String unit) {
super(parent, SWT.NONE);
setBackground(SWTResourceManager.getColor(239, 243, 248));
setBackgroundMode(SWT.INHERIT_FORCE);
GridLayout gridLayout = new GridLayout(1, false);
gridLayout.marginWidth = 35;
setLayout(gridLayout);
Composite composite = new Composite(this, SWT.NONE);
GridLayout gl_composite = new GridLayout(3, false);
gl_composite.verticalSpacing = 10;
gl_composite.horizontalSpacing = 25;
composite.setLayout(gl_composite);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setFont(SWTResourceManager.getFont("微软雅黑", 20, SWT.NORMAL));
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText("¥");
MoneyText text = new MoneyText(composite, SWT.RIGHT, unit);
text.setForeground(SWTResourceManager.getColor(204, 204, 204));
text.setFont(SWTResourceManager.getFont("微软雅黑", 20, SWT.NORMAL));
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
moneyProp.reader(text);
Label lblNewLabel_1 = new Label(composite, SWT.NONE);
lblNewLabel_1.setForeground(SWTResourceManager.getColor(157, 157, 157));
lblNewLabel_1.setText("万元");
ESepator timeSep = new ESepator(composite, SWT.HORIZONTAL);
timeSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
timeSep.setBackground(SWTResourceManager.getColor(153, 153, 153));
timeSep.setLineWidth(3);
}
@Override
public UnaryOperator<BigDecimal> get() {
return t -> Optional.ofNullable(moneyProp.get()).orElse(t);
}
@Override
public void addChangeListener(ChangeListener changeListener) {
moneyProp.addChangeListener(changeListener);
}
@Override
protected void checkSubclass() {}
}
package com.gx.obe.component.tree;
import java.util.List;
/**
* @Description: 树
* @author chenxw
*/
public interface ITree<T extends ITree<T>> {
/**
* @Description: 获取树根节点
* @author chenxw
* @return
*/
ITree<T> getRoot();
/**
* @Description: 子树列表
* @author chenxw
* @return
*/
List<? extends T> getITrees();
/**
* @Description: 名称
* @author chenxw
* @return
*/
String getName();
/**
* @Description: 键
* @author chenxw
* @return
*/
String getKey();
/**
* @Description: 值
* @author chenxw
* @param key
* @return
*/
String getValue(Object key);
}
package com.gx.obe.component.tree;
import java.util.ArrayList;
import java.util.List;
import com.gx.obe.util.utils.CollectionUtils;
/**
* @Description: 解析树
* @author chenxw
*/
public class ParseTrees<T extends ITree<T>> {
/**
* @Description: 叶子节点列表
*/
private List<Tree<T>> leafList = new ArrayList<>();
/**
* @Description: 树横向合并列表
*/
private List<TreeSpan> wideSpanList = new ArrayList<>();
/**
* @Description: 树竖向合并列表
*/
private List<TreeSpan> highSpanList = new ArrayList<>();
/**
* @Description: 高度
*/
private int height;
/**
* @Description: 叶子节点个数
*/
private int leafCount;
/**
* @Description: 空树
*/
private final Tree<T> NULL_TREE = new Tree<>();
/**
* @author chenxw
* @param iTreeList
*/
public ParseTrees(List<? extends T> iTreeList) {
if (CollectionUtils.isNull(iTreeList)) {
return;
}
initLeafList(iTreeList, 0, null);
initHeight(iTreeList, 1);
initHighSpanList();
initWideSpanList(iTreeList, 0, 0);
initLeafCount();
}
/**
* @Description: 初始化叶子节点列表
* @author chenxw
* @param iTreeList
* @param level
* @param parent
*/
private void initLeafList(List<? extends T> iTreeList, int level, Tree<T> parent) {
for (T iTree : iTreeList) {
Tree<T> tree = new Tree<>();
tree.setLevel(level);
tree.setParent(parent);
tree.setValue(iTree);
List<? extends T> iTrees = iTree.getITrees();
if (CollectionUtils.isNull(iTrees)) leafList.add(tree);
else initLeafList(iTrees, level + 1, tree);
}
}
/**
* @Description: 初始化树横向合并列表
* @author chenxw
* @param iTreeList
* @param level
* @param leafIndex
*/
private int initWideSpanList(List<? extends ITree<T>> iTreeList, int level, int leafIndex) {
for (ITree<T> iTree : iTreeList) {
List<? extends ITree<T>> iTrees = iTree.getITrees();
if (CollectionUtils.isNull(iTrees)) leafIndex++;
else {
TreeSpan span = new TreeSpan();
span.setLevel(level);
span.setLeafIndex(leafIndex);
span.setSpanCount(iTrees.size());
wideSpanList.add(span);
leafIndex = initWideSpanList(iTree.getITrees(), level + 1, leafIndex);
}
}
return leafIndex;
}
/**
* @Description: 初始化树竖向合并列表
* @author chenxw
*/
private void initHighSpanList() {
for (int i = 0; i < leafList.size(); i++) {
Tree<T> tree = leafList.get(i);
if (height > tree.getLevel()) {
TreeSpan span = new TreeSpan();
span.setLevel(tree.getLevel());
span.setLeafIndex(i);
span.setSpanCount(height - tree.getLevel());
highSpanList.add(span);
}
}
}
/**
* @Description: 初始化树的高度
* @author chenxw
* @param iTreeList
* @param level
*/
private void initHeight(List<? extends ITree<T>> iTreeList, int level) {
for (ITree<T> iTree : iTreeList) {
List<? extends ITree<T>> iTrees = iTree.getITrees();
if (CollectionUtils.isNull(iTrees)) height = Math.max(height, level);
else initHeight(iTrees, level + 1);
}
}
/**
* @Description: 初始化叶子节点的数量
* @author chenxw
*/
private void initLeafCount() {
leafCount = leafList.size();
}
/**
* @Description: 根据叶子节点索引获取叶子节点
* @author chenxw
* @param leafIndex
* @return
*/
public T get(int leafIndex) {
return leafList.get(leafIndex).getValue();
}
/**
* @Description: 根据层数及叶子节点索引获取对应包含这个叶子节点是节点
* @author chenxw
* @param level
* @param leafIndex
* @return
*/
public ITree<T> getITree(int level, int leafIndex) {
return getTree(level, leafList.get(leafIndex)).getValue();
}
/**
* @Description: 根据层数递归获取节点
* @author chenxw
* @param level
* @param tree
* @return
*/
private Tree<T> getTree(int level, Tree<T> tree) {
if (level > tree.getLevel() || level < 0) {
return NULL_TREE;
}
if (level == tree.getLevel()) {
return tree;
}
return getTree(level, tree.getParent());
}
/**
* @Description: 获取树横向合并列表
* @author chenxw
* @return
*/
public List<TreeSpan> getWideSpanList() {
return wideSpanList;
}
/**
* @Description: 获取树竖向合并列表
* @author chenxw
* @return
*/
public List<TreeSpan> getHighSpanList() {
return highSpanList;
}
/**
* @Description: 获取数的高度
* @author chenxw
* @return
*/
public int getHeight() {
return height;
}
/**
* @Description: 获取叶子节点数
* @author chenxw
* @return
*/
public int getLeafCount() {
return leafCount;
}
}
package com.gx.obe.component.tree;
/**
* @Description: 树
* @author chenxw
*/
class Tree<T extends ITree<T>> {
/**
* @Description: 层数
*/
private int level;
/**
* @Description: 父节点
*/
private Tree<T> parent;
/**
* @Description: 值
*/
private T value;
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public Tree<T> getParent() {
return parent;
}
public void setParent(Tree<T> parent) {
this.parent = parent;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
\ No newline at end of file
package com.gx.obe.component.tree;
public class TreeSpan {
private int level;
private int leafIndex;
private int spanCount;
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getLeafIndex() {
return leafIndex;
}
public void setLeafIndex(int leafIndex) {
this.leafIndex = leafIndex;
}
public int getSpanCount() {
return spanCount;
}
public void setSpanCount(int spanCount) {
this.spanCount = spanCount;
}
}
package com.gx.obe.component.utils;
import java.util.Arrays;
import java.util.Optional;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
public class CompositeUtils {
public static void disposeChildren(Composite composite) {
Arrays.stream(composite.getChildren()).forEach(Control::dispose);
}
public static void notifyMouseUp(Composite composite) {
CompositeUtils.getFirst(composite).ifPresent(t -> t.notifyListeners(SWT.MouseUp, null));
}
public static Optional<Control> getFirst(Composite composite) {
return Arrays.stream(composite.getChildren()).findFirst();
}
}
package com.gx.obe.component.verify;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.widgets.Control;
import com.gx.obe.bind.fun.Fun;
public class FormVerify {
List<Data> datas = new ArrayList<>();
public <T> void verify(Verify<T> verify, Function<T, Boolean> discontentCondition, String message) {
datas.add(new Data(verify.getVerifyControl(), Fun.of(discontentCondition).toGet(verify::get), message));
}
public void verify(Control control, Supplier<Boolean> discontentCondition, String message) {
datas.add(new Data(() -> control, discontentCondition, message));
}
public void add(FormVerify formVerify) {
datas.addAll(formVerify.getDatas());
}
public boolean isFail() {
for (Data data : datas) {
if (data.discontentCondition.get()) {
MessageDialog.openWarning(data.controlGet.get().getShell(), data.message);
data.controlGet.get().setFocus();
return true;
}
}
return false;
}
private List<Data> getDatas() {
return datas;
}
class Data {
Supplier<Control> controlGet;
Supplier<Boolean> discontentCondition;
String message;
public Data(Supplier<Control> controlGet, Supplier<Boolean> discontentCondition, String message) {
this.controlGet = controlGet;
this.discontentCondition = discontentCondition;
this.message = message;
}
}
}
package com.gx.obe.component.verify;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Text;
/**
* @Description: 整数验证监听
* @author chenxw
*/
public class IntegerVerifyListener implements VerifyListener {
private boolean negativeSupport;
/**
* @author chenxw
* @param negativeSupport
*/
public IntegerVerifyListener(boolean negativeSupport) {
this.negativeSupport = negativeSupport;
}
@Override
public void verifyText(VerifyEvent event) {
if (event.keyCode == SWT.BS || event.keyCode == SWT.DEL) {
event.doit = true;
return;
}
event.doit = false;
char myChar = event.character;
Text text = (Text) event.widget;
String textStr = text.getText();
if (myChar == '-') {
if (negativeSupport) {
if (textStr.indexOf("-") == -1) {
if (event.start == 0) {
event.doit = true;
}
}
}
} else {
// 其余的只能输入数字
if ((myChar >= '0' && myChar <= '9')) {
event.doit = true;
}
}
}
}
package com.gx.obe.component.verify;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.widgets.Text;
/**
* @Description: 金额验证接听
* @author chenxw
*/
public class MoneyVerifyListener implements VerifyListener {
private boolean negativeSupport;
private boolean tenThousand;
/**
* @author chenxw
* @param negativeSupport
* @param tenThousand
*/
public MoneyVerifyListener(boolean negativeSupport, boolean tenThousand) {
this.negativeSupport = negativeSupport;
this.tenThousand = tenThousand;
}
@Override
public void verifyText(VerifyEvent event) {
if (event.keyCode == SWT.BS || event.keyCode == SWT.DEL) {
event.doit = true;
return;
}
event.doit = false;
char myChar = event.character;
Text text = (Text) event.widget;
String textStr = text.getText();
// 当通过代码set值时
if (myChar == 0) {
event.doit = true;
}
// 当输入负号时
else if (myChar == '-') {
// 支持负数
if (negativeSupport) {
// 当前文本中没有负号
if (textStr.indexOf("-") == -1) {
// 第一次输入
if (event.start == 0) {
event.doit = true;
}
}
}
}
// 当输入小数点时
else if (myChar == '.') {
// 当前文本中没有小数点
if (textStr.indexOf(".") == -1) {
// 不是第一次输入
if (event.start != 0) {
event.doit = true;
}
}
}
// 当输入数字时
else if ((myChar >= '0' && myChar <= '9')) {
// 第一次输入
if (textStr.isEmpty()) {
event.doit = true;
} else {
String integralPart = textStr;
int indexOf = textStr.indexOf('.');
// 当前文本中有小数点时截取整数部分
if (indexOf != -1) {
integralPart = textStr.substring(0, indexOf);
}
// 当前整数部分是以负号开始时去掉负号
if (integralPart.startsWith("-")) {
integralPart = integralPart.substring(1);
}
// 去掉负号后的整数部分长度不能超过金额限定长度
if (integralPart.length() < (tenThousand ? 10 : 14)) {
event.doit = true;
}
}
}
}
}
package com.gx.obe.component.verify;
import java.util.function.Supplier;
import org.eclipse.swt.widgets.Control;
import com.gx.obe.bind.view.Read;
public interface Verify<T> extends Read<T> {
Supplier<Control> getVerifyControl();
}
\ No newline at end of file
......@@ -242,7 +242,7 @@ public class AdjustStrategyDialog extends EDialog {
String adjustReason = adjustReason_text.getText().trim();
if (VerificationUtils.ver(adjustReason_text, adjustReason::isEmpty, "调整原因不能为空!")) return;
if (evaluationStepService.isCompletePriceAndRecommendStep(tenderId)) {
if (evaluationStepService.isCompletePriceAndRecommonedStep(tenderId)) {
MessageDialog.openWarning(getShell(), "已完成价格评审或推荐中标候选人,无法调整评标价!");
return;
}
......
......@@ -28,11 +28,12 @@ import com.gx.obe.quote.listener.PatternModifyListener;
import com.gx.obe.quote.utils.VerificationUtils;
import com.gx.obe.quote.vo.BidPriceModifyVo;
import com.gx.obe.quote.vo.QuoteVo;
import com.gx.obe.util.utils.BigDecimalUtil;
import com.gx.obe.web.service.BidPriceResultService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.swtdesigner.SWTResourceManager;
import im.util.BigDecimalUtil;
/**
* @Description: 修正投标报价
* @author chenxw
......@@ -224,7 +225,7 @@ public class ModifyBidPriceDialog extends EDialog {
String modifyReason = modifyReason_text.getText();
if (VerificationUtils.ver(modifyReason_text, modifyReason::isEmpty, "修正原因不能为空!")) return;
if (evaluationStepService.isCompletePriceAndRecommendStep(tenderId)) {
if (evaluationStepService.isCompletePriceAndRecommonedStep(tenderId)) {
MessageDialog.openWarning(getShell(), "已完成价格评审或推荐中标候选人,无法修正投标价!");
return;
}
......
......@@ -61,7 +61,7 @@ public class AdjustStrategyTable extends DynamicTable {
}
private void refreshTable() {
if (!evaluationStepService.isCompletePriceAndRecommendStep(tenderId)) {
if (!evaluationStepService.isCompletePriceAndRecommonedStep(tenderId)) {
addOperateCol(new OperateColVo("操作", "调整", editImage, this::editEnablePre, this::editActionRender));
addOperateCol(new OperateColVo("操作", "重置", deleteImage, this::deleteEnablePre, this::deleteActionRender));
}
......
......@@ -78,7 +78,7 @@ public class BidPriceModifyTable extends DynamicTable {
}
private void refreshTable() {
if (!evaluationStepService.isCompletePriceAndRecommendStep(tenderId)) {
if (!evaluationStepService.isCompletePriceAndRecommonedStep(tenderId)) {
addOperateCol(new OperateColVo("操作", "修正", editImage, this::editEnablePre, this::editActionRender));
addOperateCol(new OperateColVo("操作", "重置", deleteImage, this::deleteEnablePre, this::deleteActionRender));
}
......
......@@ -32,11 +32,11 @@ public class UserUtils {
}
public static List<AuthUser> getManagerUserList(String userId) {
return Stream.of(userService.getById(userId)).collect(Collectors.toList());
return Stream.of(userService.findById(userId)).collect(Collectors.toList());
}
public static AuthUser getManagerUser(String tenderId) {
return userService.getById(tenderProjectService.getById(tenderId).getUserId());
return userService.findById(tenderProjectService.getById(tenderId).getUserId());
}
}
......@@ -55,7 +55,8 @@ public class SupplierPriceEvalResultCalculator {
Objects.requireNonNull(evaluationFactor);
this.calcuateFinalScoreFun = FactorUtils.getRealWeight(evaluationFactor.getFactorFinalWeight())::multiply;
this.supplierTotalScoreCalculator = SupplierTotalScoreCalculatorFactory.create(PropertiesUtils.getProperty(ConfigConstants.SUPPLIER_TOTAL_SCORE_CALCULATE_TYPE));
//this.supplierTotalScoreCalculator = SupplierTotalScoreCalculatorFactory.create(PropertiesUtils.getProperty(ConfigConstants.SUPPLIER_TOTAL_SCORE_CALCULATE_TYPE));
this.supplierTotalScoreCalculator = SupplierTotalScoreCalculatorFactory.create(PropertiesUtils.getProperty("SUPPLIER_TOTAL_SCORE_CALCULATE_TYPE找不到"));
}
/**
......
package com.gx.obe.step.price.creater;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationFactorEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.components.core.enumeration.PriceReviewTypeEnum;
import com.gx.obe.datastruct.tree.Forest;
import com.gx.obe.message.Messages;
import com.gx.obe.step.price.enums.PriceDetailTableColEnum;
import com.gx.obe.step.price.utils.FactorUtils;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.UuidUtils;
import com.gx.obe.web.entity.evaluation.EvaluationFactor;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
public class DefaultPriceEvalStepCreater {
private String tenderId;
private Map<Boolean, List<EvaluationFactor>> priceFactorListMap;
public DefaultPriceEvalStepCreater(String tenderId, List<EvaluationFactor> priceFactorList) {
this.tenderId = tenderId;
this.priceFactorListMap = new Forest<>(priceFactorList).getLeafList().stream().collect(Collectors.partitioningBy(t -> PriceDetailTableColEnum.contain(t.getBidPriceCode(), PriceDetailTableColEnum.TypeEnum.PRICE)));
}
public List<PriceEvalStep> createSingle() {
List<PriceEvalStep> evalStepList = new ArrayList<>();
createDetail(evalStepList);
List<EvaluationFactor> evaluationFactorList = priceFactorListMap.get(false);
if (!evaluationFactorList.isEmpty()) {
PriceEvalStep evalStep = create();
evalStep.getPriceStep().setStepName(Messages.Step_price);
evalStep.getPriceStep().setScore(evaluationFactorList.stream().map(t -> t.getFactorScore()).reduce(null, BigDecimalUtils::add));
evalStep.getPriceStep().setWeight(evaluationFactorList.stream().map(this::getPriceStepWeight).reduce(null, BigDecimalUtils::add));
evalStep.getPriceStep().setEvaluationParam(EvaluationStepEnum.PRICE_REVIEW_TYPE, PriceReviewTypeEnum.PRICE);
evalStep.getFactorList().addAll(evaluationFactorList);
evalStepList.add(evalStep);
}
return evalStepList;
}
public List<PriceEvalStep> createMulty() {
List<PriceEvalStep> evalStepList = new ArrayList<>();
createDetail(evalStepList);
for (EvaluationFactor evaluationFactor : priceFactorListMap.get(false)) {
PriceEvalStep evalStep = create();
evalStep.getPriceStep().setStepName(evaluationFactor.getFactorName());
evalStep.getPriceStep().setScore(evaluationFactor.getFactorScore());
evalStep.getPriceStep().setWeight(getPriceStepWeight(evaluationFactor));
evalStep.getPriceStep().setEvaluationParam(EvaluationStepEnum.PRICE_REVIEW_TYPE, PriceReviewTypeEnum.PRICE);
evalStep.getFactorList().add(evaluationFactor);
evalStepList.add(evalStep);
}
return evalStepList;
}
private void createDetail(List<PriceEvalStep> evalStepList) {
for (EvaluationFactor evaluationFactor : priceFactorListMap.get(true)) {
PriceEvalStep evalStep = create();
evalStep.getPriceStep().setStepName(evaluationFactor.getFactorName());
evalStep.getPriceStep().setScore(evaluationFactor.getFactorScore());
evalStep.getPriceStep().setWeight(getPriceStepWeight(evaluationFactor));
evalStep.getPriceStep().setEvaluationParam(EvaluationStepEnum.PRICE_REVIEW_TYPE, PriceReviewTypeEnum.DETAIL);
evalStep.getFactorList().add(evaluationFactor);
evalStepList.add(evalStep);
}
}
private PriceEvalStep create() {
EvaluationStep priceStep = new EvaluationStep();
List<EvaluationFactor> factorList = new ArrayList<>();
priceStep.setId(UuidUtils.getUUID());
priceStep.setTenderId(tenderId);
priceStep.setStepType(EvaluationStepEnum.PRICE);
priceStep.setFilterType(EvaluationStepEnum.FILTER_NO);
priceStep.setStepStatus(CommonEnum.NOT_START);
priceStep.setEvalBidType(EvaluationFactorEnum.EVAL_BID_PRICE);
priceStep.setRoleType(EvaluationStepEnum.EXPERT_LEADER);
PriceEvalStep priceEvalStep = new PriceEvalStep();
priceEvalStep.setPriceStep(priceStep);
priceEvalStep.setFactorList(factorList);
return priceEvalStep;
}
private BigDecimal getPriceStepWeight(EvaluationFactor evaluationFactor) {
return evaluationFactor.getFactorScore().multiply(FactorUtils.getRealWeight(evaluationFactor.getFactorFinalWeight()));
}
}
//package com.gx.obe.step.price.creater;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
//import com.gx.obe.components.core.enumeration.CommonEnum;
//import com.gx.obe.components.core.enumeration.EvaluationFactorEnum;
//import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
//import com.gx.obe.components.core.enumeration.PriceReviewTypeEnum;
//import com.gx.obe.datastruct.tree.Forest;
//import com.gx.obe.message.Messages;
//import com.gx.obe.step.price.enums.PriceDetailTableColEnum;
//import com.gx.obe.step.price.utils.FactorUtils;
//import com.gx.obe.util.utils.BigDecimalUtils;
//import com.gx.obe.util.utils.UuidUtils;
//import com.gx.obe.web.entity.evaluation.EvaluationFactor;
//import com.gx.obe.web.entity.evaluation.EvaluationStep;
//
//public class DefaultPriceEvalStepCreater {
//
// private String tenderId;
// private Map<Boolean, List<EvaluationFactor>> priceFactorListMap;
//
// public DefaultPriceEvalStepCreater(String tenderId, List<EvaluationFactor> priceFactorList) {
// this.tenderId = tenderId;
// this.priceFactorListMap = new Forest<>(priceFactorList).getLeafList().stream().collect(Collectors.partitioningBy(t -> PriceDetailTableColEnum.contain(t.getBidPriceCode(), PriceDetailTableColEnum.TypeEnum.PRICE)));
// }
//
// public List<PriceEvalStep> createSingle() {
// List<PriceEvalStep> evalStepList = new ArrayList<>();
// createDetail(evalStepList);
// List<EvaluationFactor> evaluationFactorList = priceFactorListMap.get(false);
// if (!evaluationFactorList.isEmpty()) {
// PriceEvalStep evalStep = create();
// evalStep.getPriceStep().setStepName(Messages.Step_price);
// evalStep.getPriceStep().setScore(evaluationFactorList.stream().map(t -> t.getFactorScore()).reduce(null, BigDecimalUtils::add));
// evalStep.getPriceStep().setWeight(evaluationFactorList.stream().map(this::getPriceStepWeight).reduce(null, BigDecimalUtils::add));
// evalStep.getPriceStep().setEvaluationParam(EvaluationStepEnum.PRICE_REVIEW_TYPE, PriceReviewTypeEnum.PRICE);
// evalStep.getFactorList().addAll(evaluationFactorList);
// evalStepList.add(evalStep);
// }
// return evalStepList;
// }
//
// public List<PriceEvalStep> createMulty() {
// List<PriceEvalStep> evalStepList = new ArrayList<>();
// createDetail(evalStepList);
// for (EvaluationFactor evaluationFactor : priceFactorListMap.get(false)) {
// PriceEvalStep evalStep = create();
// evalStep.getPriceStep().setStepName(evaluationFactor.getFactorName());
// evalStep.getPriceStep().setScore(evaluationFactor.getFactorScore());
// evalStep.getPriceStep().setWeight(getPriceStepWeight(evaluationFactor));
// evalStep.getPriceStep().setEvaluationParam(EvaluationStepEnum.PRICE_REVIEW_TYPE, PriceReviewTypeEnum.PRICE);
// evalStep.getFactorList().add(evaluationFactor);
// evalStepList.add(evalStep);
// }
// return evalStepList;
// }
//
// private void createDetail(List<PriceEvalStep> evalStepList) {
// for (EvaluationFactor evaluationFactor : priceFactorListMap.get(true)) {
// PriceEvalStep evalStep = create();
// evalStep.getPriceStep().setStepName(evaluationFactor.getFactorName());
// evalStep.getPriceStep().setScore(evaluationFactor.getFactorScore());
// evalStep.getPriceStep().setWeight(getPriceStepWeight(evaluationFactor));
// evalStep.getPriceStep().setEvaluationParam(EvaluationStepEnum.PRICE_REVIEW_TYPE, PriceReviewTypeEnum.DETAIL);
// evalStep.getFactorList().add(evaluationFactor);
// evalStepList.add(evalStep);
// }
// }
//
// private PriceEvalStep create() {
// EvaluationStep priceStep = new EvaluationStep();
// List<EvaluationFactor> factorList = new ArrayList<>();
// priceStep.setId(UuidUtils.getUUID());
// priceStep.setTenderId(tenderId);
// priceStep.setStepType(EvaluationStepEnum.PRICE);
// priceStep.setFilterType(EvaluationStepEnum.FILTER_NO);
// priceStep.setStepStatus(CommonEnum.NOT_START);
// priceStep.setEvalBidType(EvaluationFactorEnum.EVAL_BID_PRICE);
// priceStep.setRoleType(EvaluationStepEnum.EXPERT_LEADER);
//
// PriceEvalStep priceEvalStep = new PriceEvalStep();
// priceEvalStep.setPriceStep(priceStep);
// priceEvalStep.setFactorList(factorList);
// return priceEvalStep;
// }
//
// private BigDecimal getPriceStepWeight(EvaluationFactor evaluationFactor) {
// return evaluationFactor.getFactorScore().multiply(FactorUtils.getRealWeight(evaluationFactor.getFactorFinalWeight()));
// }
//
//}
......@@ -57,7 +57,9 @@ public enum PriceDetailTableColEnum {
/**
* @Description: keyMap
*/
public static Map<String, PriceDetailTableColEnum> PRICE_MAP = EnumUtils.toMap(values(), PriceDetailTableColEnum::getKey, PredicateUtils.map(PriceDetailTableColEnum::getTypeEnum, Predicate.isEqual(TypeEnum.PRICE)));
//public static Map<String, PriceDetailTableColEnum> PRICE_MAP = EnumUtils.toMap(values(), PriceDetailTableColEnum::getKey, PredicateUtils.map(PriceDetailTableColEnum::getTypeEnum, Predicate.isEqual(TypeEnum.PRICE)));
//类缺少内容
public static Map<String, PriceDetailTableColEnum> PRICE_MAP = new HashMap<String,PriceDetailTableColEnum>();
/**
* @Description: key列表缓存
......
......@@ -119,14 +119,16 @@ public class SupplierTreeTable extends KTable {
private void initTableRowCol() {
tableColList.add(new TableCol("序号", i -> String.valueOf(i + 1)));
String type = PropertiesUtils.getProperty(ConfigConstants.SHOW_PRICE_DETAIL_COL_CONTENT_TYPE);
//String type = PropertiesUtils.getProperty(ConfigConstants.SHOW_PRICE_DETAIL_COL_CONTENT_TYPE);
String type = PropertiesUtils.getProperty("");
Function<Integer, PriceDetail> getPriceDetailByIndex = priceDetailList::get;
tableColList.add(new TableCol("报价明细", getPriceDetailByIndex.andThen(priceDetailColContentFun(type)).andThen(ObjectUtils::getObjString)));
Function<String, BigDecimal> basePriceFun = evalResultList.stream().collect(Collectors.toMap(PriceDetailEvalResult::getDetailCode, PriceDetailEvalResult::getBasePrice))::get;
tableColList.add(new TableCol("基准价(" + projectRule.getPriceUnit() + ")", getPriceDetailByIndex.andThen(PriceDetail::getDetailCode).andThen(basePriceFun).andThen(this::formatPrice)));
if (PropertiesUtils.getProperty(ConfigConstants.SUPPLIER_TREE_TABLE_SHOW_WEIGHT, CommonEnum.NO).equals(CommonEnum.YES))
//if (PropertiesUtils.getProperty(ConfigConstants.SUPPLIER_TREE_TABLE_SHOW_WEIGHT, CommonEnum.NO).equals(CommonEnum.YES))
if (PropertiesUtils.getProperty(CommonEnum.NO, CommonEnum.NO).equals(CommonEnum.YES))
tableColList.add(new TableCol("权重(%)", getPriceDetailByIndex.andThen(PriceDetail::getScoreWeight).andThen(ObjectUtils::getObjString)));
Function<Object, EvaluationFactorResult> evaluationFactorResultFun = factorResultList.stream().collect(Collectors.toMap(EvaluationFactorResult::getSupplierId, Function.identity()))::get;
......
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Struct
Bundle-SymbolicName: com.gx.obe.struct
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.gx.obe.struct.Activator
Bundle-Vendor: GX
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
com.gx.obe.lib;bundle-version="1.0.0",
com.gx.obe.utils;bundle-version="1.0.0",
com.gx.obe.components.core,
com.gx.obe.business;bundle-version="1.0.0",
org.eclipse.swt.core,
com.gx.obe.common.file;bundle-version="1.0.0",
com.gx.obe.bind,
com.gx.obe.common.icons,
com.gx.obe.component,
com.gx.obe.common.widget,
com.gx.obe.step,
com.gx.obe.action,
com.gx.obe.common
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: com.gx.obe.struct
Bundle-ActivationPolicy: lazy
Export-Package: com.gx.obe.struct,
com.gx.obe.struct.action,
com.gx.obe.struct.beans,
com.gx.obe.struct.composite,
com.gx.obe.struct.dialog,
com.gx.obe.struct.enums,
com.gx.obe.struct.handler,
com.gx.obe.struct.inters,
com.gx.obe.struct.listener,
com.gx.obe.struct.service,
com.gx.obe.struct.thread,
com.gx.obe.struct.tree,
com.gx.obe.struct.utils
Import-Package: com.gx.obe.action.bean,
com.gx.obe.config,
com.gx.obe.config.utils,
com.gx.obe.message
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment