public DataItemHolder ( final BundleContext context, final Item item, final DataSourceListener listener ) { super ( context, item, null ); this.listener = listener; this.observer = new Observer () { @Override public void update ( final Observable o, final Object arg ) { DataItemHolder.this.update ( o, arg ); } }; init (); }
public void start() { runBeforeActions(); setStartTime(System.nanoTime()); downloader.download(); downloader.deleteObservers(); downloader.addObserver(new Observer() { @Override public void update(Observable arg0, Object arg1) { if (downloader.getStatus() == Downloader.COMPLETED) { runAfterActions(); } } }); }
@Override protected Observer createErrorListener() { return new Observer() { @Override public void update(Observable observable, Object arg) { if (arg != null) { FormatError error = (FormatError) arg; if (error.getNumbers() .size() > 1) { int line = error.getNumbers() .get(0); int column = error.getNumbers() .get(1); select(line, column); } } } }; }
/** Creates the listener of the error panel. */ private Observer createErrorListener() { return new Observer() { @Override public void update(Observable o, Object arg) { if (arg != null) { AspectJCell errorCell = getJGraph().getModel() .getErrorMap() .get(arg); if (errorCell != null) { getJGraph().setSelectionCell(errorCell); } } } }; }
void installListeners() { getJGraph().addPropertyChangeListener(org.jgraph.JGraph.GRAPH_MODEL_PROPERTY, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { updateModel(); } }); getJGraph().addGraphSelectionListener(new GraphSelectionListener() { @Override public void valueChanged(GraphSelectionEvent e) { clearSelection(); } }); getFilter().addObserver(new Observer() { @Override @SuppressWarnings("unchecked") public void update(Observable o, Object arg) { LabelTree.this.repaint(); getJGraph().refreshCells((Set<JCell<G>>) arg); } }); addMouseListener(new MyMouseListener()); }
@Override public void initialize() { super.initialize(); // We run this code in the "initialize" method and not in the constructor, // because at the time the constructor is run, the "actor" field of the // test action is not yet populated. if (!AppiumTestAction.initialized) { AppiumTestAction.initialized = true; this.getActor().addObserver(new Observer() { @Override public void update(Observable eventSource, Object eventData) { if (eventSource instanceof ITestActor) { if (eventData == TestActorEvents.TEST_COMPLETED) { if (!AppiumHelper.getConfig().getBoolean("appium.reuseDriver", false)) { AppiumHelper.discardDriver(); } } } } }); } }
@Test public void testImportExcelSingletonSuccess() { ResetTestValue.reset(); ImportHandler handler = new ImportHandler( new RowRecordHandlerImpl(), new RowRecordPersistencorHibernateImpl(factory), TransactionMode.SINGLETON); List<RowRecord> list = handler.importExcel( ExcelFactory.newExcel(new File("D:/test/schoolman.xlsx")), new Observer() { @Override public void update(Observable o, Object arg) { Process process = (Process) arg; System.out.println("进度:" + process.getProcess() + ",当前阶段:" + process.getNode()); } }, SchoolMan.class); for (RowRecord rr : list) { System.out.println(rr.getResult().getMsg()); } }
@Test public void testImportExcelSingletonError() { ResetTestValue.reset(); ImportHandler handler = new ImportHandler( new RowRecordPersistencorHibernateImpl(factory), TransactionMode.SINGLETON); List<RowRecord> list = handler.importExcel( ExcelFactory.newExcel(new File("D:/test/schoolman_error.xlsx")), new Observer() { @Override public void update(Observable o, Object arg) { Process process = (Process) arg; System.out.println("进度:" + process.getProcess() + ",当前阶段:" + process.getNode()); } }, SchoolMan.class); for (RowRecord rr : list) { System.out.println("行号:" + rr.getRowNo() + ", 错误信息:" + rr.getResult().getMsg()); } }
@Test public void testImportExcelMultipleSuccess() { ResetTestValue.reset(); ImportHandler handler = new ImportHandler( new RowRecordPersistencorHibernateImpl(factory), TransactionMode.MULTIPLE); List<RowRecord> list = handler.importExcel( ExcelFactory.newExcel(new File("D:/test/schoolman.xlsx")), new Observer() { @Override public void update(Observable o, Object arg) { Process process = (Process) arg; System.out.println("进度:" + process.getProcess() + ",当前阶段:" + process.getNode()); } }, SchoolMan.class); for (RowRecord rr : list) { System.out.println(rr.getResult().getMsg()); } }
public static void main(String[] args) { Observer observer1 = new WeatherObserver(); Observer observer2 = new WeatherObserver(); Observer observer3 = new WeatherObserver(); WeatherSubject weatherSubject = new WeatherSubject.Builder("Shanghai") .temperature(22f) .humidity(0.8f) .forecastTemperatures(Arrays.asList(0.5f, 0.8f, 1.5f)) .build(); weatherSubject.addObserver(observer1); weatherSubject.addObserver(observer2); weatherSubject.addObserver(observer3); weatherSubject.setWeatherSubject(new WeatherSubject.Builder("Shanghai") .temperature(28f) .humidity(9.8f) .forecastTemperatures(Arrays.asList(2.5f, 8.8f, 4.5f))); }
@Test public void testWeaterObserver() throws Exception { Observer observer1 = mock(WeatherObserver.class); Observer observer2 = mock(WeatherObserver.class); WeatherSubject weatherSubject = new WeatherSubject.Builder("Shanghai") .temperature(22f) .humidity(0.8f) .forecastTemperatures(Arrays.asList(0.5f, 0.8f, 1.5f)) .build(); weatherSubject.addObserver(observer1); weatherSubject.addObserver(observer2); weatherSubject.setWeatherSubject(new WeatherSubject.Builder("Shanghai") .temperature(28f) .humidity(9.8f) .forecastTemperatures(Arrays.asList(2.5f, 8.8f, 4.5f))); verify(observer1).update(weatherSubject, null); verify(observer2).update(weatherSubject, null); }
private void startGps() { locationObserver = new Observer() { @Override public void update(Observable o, Object arg) { Log.i(TAG, "update: Stopping Location"); LocationProxy.getInstance().stopRequest(getApplicationContext()); } }; Log.i(TAG, "onCreate: AddObserver"); LocationProxy.getInstance().addObserver(locationObserver); //Initializing location if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSION_GPS); else LocationProxy.getInstance().startRequest(this); }
public static void main(String[] args) { System.err.println( "\nTest creating proxy class with the null class loader.\n"); try { ClassLoader ld = null; Class p = Proxy.getProxyClass(ld, new Class[] { Runnable.class, Observer.class }); System.err.println("proxy class: " + p); ClassLoader loader = p.getClassLoader(); System.err.println("proxy class's class loader: " + loader); if (loader != null) { throw new RuntimeException( "proxy class not defined in the null class loader"); } System.err.println("\nTEST PASSED"); } catch (Throwable e) { System.err.println("\nTEST FAILED:"); e.printStackTrace(); throw new RuntimeException("TEST FAILED: " + e.toString()); } }
public MacroViewer() { setLayout(new BorderLayout()); macroTable = new ExtendedJTable(dataModel, true, false, true); macroTable.setRowHeight(PropertyPanel.VALUE_CELL_EDITOR_HEIGHT); macroTable.setRowHighlighting(true); scrollPane = new ExtendedJScrollPane(macroTable); scrollPane.setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 5)); add(scrollPane, BorderLayout.CENTER); updateQueue = new UpdateQueue(MACRO_VIEWER_DOCK_KEY); updateQueue.start(); macroObserver = new Observer() { @Override public void update(Observable o, Object arg) { updateQueue.execute(new Runnable() { @Override public void run() { updateMacros(); try { Thread.sleep(1000); // Sleep 1sec to avoid update flooding } catch (InterruptedException e) { } } }); } }; }
private void attach ( final ConnectionService connectionService ) { detach (); this.item = new DataItem ( this.itemDescriptor.getItemId () ); this.item.addObserver ( new Observer () { @Override public void update ( final Observable o, final Object arg ) { ItemRegistration.this.handleUpdate ( (DataItemValue)arg ); } } ); this.item.register ( connectionService.getItemManager () ); }
private Observer createObserver () { return new Observer () { @Override public void update ( final Observable o, final Object arg ) { if ( arg instanceof DataItemValue ) { handleUpdate ( this, (DataItemValue)arg ); } } }; }
protected synchronized void handleUpdate ( final Observer observer, DataItemValue value ) { if ( observer != this.observer ) { return; } if ( this.invalidValuePolicy.isInvalid ( value ) ) { value = this.invalidValuePolicy.processInvalid ( value ); } fireChange ( this.value, this.value = value ); }
public void setNewGraphVersionObserver(List<Observer> observers) { if (observers != null) { for (Observer observer : observers) { addObserver(observer); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_input_arrival); setTitle(R.string.titleArrival); txtArrivalDate = (TextView) findViewById(R.id.txtArrivalDate); txtArrivalTime = (TextView) findViewById(R.id.txtArrivalTime); txtArrivalStation = (TextView) findViewById(R.id.txtLocation); Bundle data = getIntent().getExtras(); currentTravel = data.getParcelable("travel"); setArrivalDateTime(GregorianCalendar.getInstance()); locationObserver = new Observer() { @Override public void update(Observable o, Object arg) { Log.i(TAG, "update: Stopping Location"); LocationProxy.getInstance().stopRequest(getApplicationContext()); autoSelectStation(); } }; Log.i(TAG, "onCreate: AddObserver"); LocationProxy.getInstance().addObserver(locationObserver); autoSelectStation(); }
private Observer createErrorListener() { return new Observer() { @Override public void update(Observable o, Object arg) { FormatError error = (FormatError) arg; if (error != null) { getSimulatorModel().setState(error.getState()); } } }; }
@Override protected Observer createErrorListener() { return new Observer() { @Override public void update(Observable o, Object arg) { if (arg != null) { JCell<?> errorCell = getJModel().getErrorMap() .get(arg); if (errorCell != null) { getJGraph().setSelectionCell(errorCell); } } } }; }
/** * Creates an observer for the error panel that will select the * erroneous part of the resource upon selection of an error. */ private Observer createListListener() { return new Observer() { @Override public void update(Observable observable, Object arg) { if (arg != null) { selectDisplayPart((SelectableListEntry) arg); } } }; }
/** * Adds the specified observer to the list of observers. If it is already * registered, it is not added a second time. * * @param observer the Observer to add. */ public void addObserver(Observer observer) { if (observer == null) { throw new NullPointerException("observer == null"); } observers.add(observer); }
@Test public void save_notifies_about_change() { final Observer observable = Mockito.mock(Observer.class); saver.addObserver(observable); saver.save("cat", "key1", "val1"); Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any()); }
@Test public void update_notifies_about_change() { final Observer observable = Mockito.mock(Observer.class); saver.save("cat", "key1", "val1"); saver.addObserver(observable); saver.save("cat", "key1", "val2"); Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any()); }
@Test public void remove_key_notifies_about_change() { final Observer observable = Mockito.mock(Observer.class); saver.save("cat", "key1", "val1"); saver.addObserver(observable); saver.remove("cat", "key1"); Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any()); }
@Test public void remove_category_notifies_about_change() { final Observer observable = Mockito.mock(Observer.class); saver.save("cat", "key1", "val1"); saver.addObserver(observable); saver.remove("cat"); Mockito.verify(observable).update(Mockito.eq(saver), Mockito.any()); }
/** * <p>导入excel方法</p> * * @param excel 需要导入的excel对象 * @param sheetNo excel中sheet的编号 * @param processObserver 进度处理器 * @param pojos 导入对象的pojo类 * @return RowRecord的list,通过getResult可以获取导入结果 */ public List<RowRecord> importExcel(AbstractExcel excel, int sheetNo, Observer processObserver, Class<?>... pojos) { List<Map<String, Object>> excelDataList = excel.readExcel(sheetNo); List<RowRecord> rowRecordList = new ArrayList<>(); for (int i = 0; i < excelDataList.size(); i ++) { Map<String, Object> excelData = excelDataList.get(i); rowRecordList.add(handler.rowRecordCreate(excelData, i + 2)); } // 根据repairer判断有3或4个步骤,进度为处理数量*3或4 int step = 3; if (repairer != null) step = 4; Process process = null; if (processObserver != null) { process = new Process((long) (rowRecordList.size() * step)); process.addObserver(processObserver); } // 步骤1 if (!handler.handle(rowRecordList, process, pojos) && mode == TransactionMode.MULTIPLE) return rowRecordList; // 步骤2 if (!validator.valid(rowRecordList, process) && mode == TransactionMode.MULTIPLE) return rowRecordList; // 步骤3 持久化前修正rowRecord,如:密码md5加密转换 if (repairer != null) repaire(rowRecordList, process); // 步骤4 persistencor.persist(rowRecordList, mode, process); return rowRecordList; }
@FXML void initialize() { messageTf.setText(model.getMessage()); model.addObserver(new Observer() { public void update(Observable o, Object arg) { messageTf.setText(model.getMessage()); } }); }
/** * Allows another module to put an observer into the current module. * * @param o - the observer to be added */ public void addObserver(Observer o) { observable.addObserver(o); // notify to remove the gui key event dispatcher observable.notifyObservers(ObservedActions.Action.REMOVE_GUI_KEY_EVENT_DISPATCHER); }
public void setBidAmount(Observer observer,BigDecimal newBidAmount){ System.out.println("-----------------New bid placed----------------"); int res=bidAmount.compareTo(newBidAmount); if(res==-1){ this.observer=observer; this.bidAmount=newBidAmount; setChanged(); notifyObservers(); } else { System.out.println("New bid amount cannot be less or equal to current bid amount: "+this.bidAmount); } }
public void addTask(Observer task) { super.addObserver(task); }
void addObserver(Observer observer) { observable.addObserver(observer); }
public void GetBookUpdates(Observer o) { book_data.addObserver(o); }
/** Used to inform the validator about the ColumnMetaData object **/ @Override public synchronized void addObserver(Observer o) { super.addObserver(o); }
protected Observer getObserver() { return (this.observer); }
public void addObservers(Observer observer) { pressedButtonId.addObserver(observer); currentEvent.addObserver(observer); }