001package org.vishia.guiBzr; 002 003import java.text.DateFormat; 004import java.text.SimpleDateFormat; 005import java.util.Date; 006import java.util.concurrent.ConcurrentLinkedQueue; 007 008import org.vishia.cmd.CmdExecuter; 009import org.vishia.gral.area9.GralArea9_ifc; 010import org.vishia.gral.base.GralTextBox; 011import org.vishia.gral.base.GralTextField; 012import org.vishia.gral.ifc.GralMngBuild_ifc; 013import org.vishia.gral.ifc.GralMng_ifc; 014import org.vishia.gral.ifc.GralTableLine_ifc; 015import org.vishia.gral.ifc.GralWindow_ifc; 016import org.vishia.mainCmd.MainCmd_ifc; 017 018public class MainData 019{ 020 021 final MainCmd_ifc mainCmdifc; 022 023 final CmdExecuter cmdExec = new CmdExecuter(); 024 025 /**Access to all panels of this application. */ 026 final BzrGui panels; 027 028 MainAction mainAction; 029 030 GralMng_ifc panelAccess; 031 032 GralArea9_ifc guifc; 033 034 final DataConfig cfg = new DataConfig(); 035 036 /**The current selected software project. */ 037 DataProject currPrj; 038 039 /**The current selected component. */ 040 DataCmpn currCmpn; 041 042 043 /**The current selected line. */ 044 GralTableLine_ifc currTableline; 045 046 047 final BzrGetStatus getterStatus; 048 049 final DateFormat dateFormatShowingFull = new SimpleDateFormat("yy-MM-dd HH:mm"); 050 final DateFormat dateFormatShowingHour = new SimpleDateFormat("HH:mm"); 051 052 /**Only one command invocation should be active in one time. */ 053 //final ProcessBuilder cmdMng = new ProcessBuilder(""); 054 055 private final ConcurrentLinkedQueue<Runnable> ordersBackground =new ConcurrentLinkedQueue<Runnable>(); 056 057 /**Data of the currently selected component. 058 * 059 */ 060 DataCmpn selectedCmpn; 061 062 063 GralWindow_ifc infoWindow; 064 065 GralTextBox infoBox; 066 067 GralTextField infoLine; 068 069 070 071 MainData(MainCmd_ifc mainCmd, BzrGui panels) 072 { 073 this.mainCmdifc = mainCmd; 074 this.panels = panels; 075 getterStatus = new BzrGetStatus(mainCmd, this); 076 077 } 078 079 080 void addOrderBackground(Runnable order) 081 { 082 ordersBackground.add(order); 083 synchronized(ordersBackground){ 084 ordersBackground.notify(); 085 } 086 } 087 088 089 /**Gets a order. Waits a defined time, then returns also if no order is given. 090 * @return 091 */ 092 Runnable awaitOrderBackground(int timeout) 093 { 094 Runnable order; 095 if(ordersBackground.isEmpty()){ 096 try{ 097 synchronized(ordersBackground) 098 { ordersBackground.wait(timeout); } 099 } 100 catch (InterruptedException e){} 101 } 102 if(!ordersBackground.isEmpty()){ 103 order = ordersBackground.poll(); 104 } else { 105 order = null; 106 } 107 return order; 108 } 109 110 111 /**Formats the given date into a String using 'yesterday' and 'today' if possible 112 * @param date 113 * @return 114 */ 115 String formatTimestampYesterday(long date) 116 { String ret; 117 Date date1 = new Date(date); 118 long millisecPerday = 24*3600*1000; 119 long dateToday = System.currentTimeMillis() / millisecPerday * millisecPerday; 120 if(date >= dateToday && date < dateToday + millisecPerday){ 121 ret = " today " + dateFormatShowingHour.format(date1); 122 } else if(date >= dateToday - millisecPerday && date < dateToday){ 123 ret = "yesterday " + dateFormatShowingHour.format(date1); 124 } else { 125 ret = dateFormatShowingFull.format(date1); 126 } 127 return ret; 128 } 129 130 131}