List of usage examples for java.util EventObject getSource
public Object getSource()
From source file:it.geosolutions.geobatch.geoserver.shapefile.ShapeFileAction.java
private static File toFile(EventObject eo) { Object o = eo.getSource(); if (o instanceof File) { return (File) o; } else {/* w ww . j ava 2s.com*/ return null; } }
From source file:TestEventSource.java
public void handleEvent(EventObject o) { System.out.println(id + " called"); if (id.equals("C")) { ((TestEventSource) o.getSource()).removeListener(this); }/*from www .ja v a 2 s. com*/ }
From source file:Main.java
@Override public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent && e.getSource() instanceof JTree) { MouseEvent me = (MouseEvent) e; JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(me.getX(), me.getY()); Rectangle r = tree.getPathBounds(path); if (r == null) { return false; }//w w w .ja v a 2 s.c o m Dimension d = check.getPreferredSize(); r.setSize(new Dimension(d.width, r.height)); if (r.contains(me.getX(), me.getY())) { check.setBounds(new Rectangle(0, 0, d.width, r.height)); return true; } } return false; }
From source file:com.prime.app.agvirtual.web.jsf.InputFileController.java
/** * <p>This method is bound to the inputFile component and is executed * multiple times during the file upload process. Every call allows * the user to finds out what percentage of the file has been uploaded. * This progress information can then be used with a progressBar component * for user feedback on the file upload progress. </p> * * @param event holds a InputFile object in its source which can be probed * for the file upload percentage complete. *//* w w w . j a v a 2s . c om*/ public void fileUploadProgress(EventObject event) { InputFile ifile = (InputFile) event.getSource(); fileProgress = ifile.getFileInfo().getPercent(); }
From source file:Main.java
@Override public boolean isCellEditable(final EventObject event) { Object source = event.getSource(); if (!(source instanceof JTree) || !(event instanceof MouseEvent)) { return false; }/*from ww w . j a v a 2 s. c om*/ JTree tree = (JTree) source; MouseEvent mouseEvent = (MouseEvent) event; TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (path == null) { return false; } Object node = path.getLastPathComponent(); if (node == null || !(node instanceof DefaultMutableTreeNode)) { return false; } Rectangle r = tree.getPathBounds(path); if (r == null) { return false; } Dimension d = panel.getPreferredSize(); r.setSize(new Dimension(d.width, r.height)); if (r.contains(mouseEvent.getX(), mouseEvent.getY())) { Point pt = SwingUtilities.convertPoint(tree, mouseEvent.getPoint(), panel); Object o = SwingUtilities.getDeepestComponentAt(panel, pt.x, pt.y); if (o instanceof JComboBox) { comboBox.showPopup(); } else if (o instanceof Component) { Object oo = SwingUtilities.getAncestorOfClass(JComboBox.class, (Component) o); if (oo instanceof JComboBox) { comboBox.showPopup(); } } return true; } return delegate.isCellEditable(event); }
From source file:gtu._work.ui.LoadJspCheckTagUI.java
private void jTreeListener(EventObject evt) { try {/*w w w . j a v a 2s . c o m*/ DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((JTree) (evt.getSource())) .getLastSelectedPathComponent(); Object userObj = node.getUserObject(); if (userObj != null && userObj instanceof ChieldNode) { File file = ((ChieldNode) userObj).file; if (modifyFileBox.getSelectedItem().equals("??")) { File tempFile = File.createTempFile(file.getName().substring(0, file.getName().length() - 5), ".java"); byte[] content = FileUtil.loadFromFile(file); FileUtil.saveToFile(tempFile, content); Runtime.getRuntime().exec("cmd /c start " + tempFile.getAbsolutePath()); tempFile.deleteOnExit(); } else { Runtime.getRuntime().exec("cmd /c start " + file.getAbsolutePath()); } } } catch (Exception e) { e.printStackTrace(); JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(e.getMessage(), "error"); } }
From source file:it.geosolutions.geobatch.actions.commons.CollectorAction.java
/** * Removes TemplateModelEvents from the queue and put *//*from www . j a va 2 s . co m*/ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { listenerForwarder.started(); listenerForwarder.setTask("build the output absolute file name"); // return final Queue<EventObject> ret = new LinkedList<EventObject>(); listenerForwarder.setTask("Building/getting the root data structure"); if (conf.getWildcard() == null) { LOGGER.warn("Null wildcard: using default\'*\'"); conf.setWildcard("*"); } it.geosolutions.tools.io.file.Collector collector = new it.geosolutions.tools.io.file.Collector( new WildcardFileFilter(conf.getWildcard(), IOCase.INSENSITIVE), conf.getDeep()); while (!events.isEmpty()) { final EventObject event = events.remove(); if (event == null) { // TODO LOG continue; } File source = null; if (event.getSource() instanceof File) { source = ((File) event.getSource()); } if (source == null || !source.exists()) { // LOG continue; } listenerForwarder.setTask("Collecting from" + source); List<File> files = collector.collect(source); if (files == null) { return ret; } for (File file : files) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Collected file: " + file); } ret.add(new FileSystemEvent(file, FileSystemEventType.FILE_ADDED)); } } listenerForwarder.completed(); return ret; }
From source file:it.geosolutions.geobatch.mail.SendMailAction.java
public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { final Queue<EventObject> ret = new LinkedList<EventObject>(); while (events.size() > 0) { final EventObject ev; try {/*from w w w .j a va 2 s .c o m*/ if ((ev = events.remove()) != null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Send Mail action.execute(): working on incoming event: " + ev.getSource()); } File mail = (File) ev.getSource(); FileInputStream fis = new FileInputStream(mail); String kmlURL = IOUtils.toString(fis); // ///////////////////////////////////////////// // Send the mail with the given KML URL // ///////////////////////////////////////////// // Recipient's email ID needs to be mentioned. String mailTo = conf.getMailToAddress(); // Sender's email ID needs to be mentioned String mailFrom = conf.getMailFromAddress(); // Get system properties Properties properties = new Properties(); // Setup mail server String mailSmtpAuth = conf.getMailSmtpAuth(); properties.put("mail.smtp.auth", mailSmtpAuth); properties.put("mail.smtp.host", conf.getMailSmtpHost()); properties.put("mail.smtp.starttls.enable", conf.getMailSmtpStarttlsEnable()); properties.put("mail.smtp.port", conf.getMailSmtpPort()); // Get the default Session object. final String mailAuthUsername = conf.getMailAuthUsername(); final String mailAuthPassword = conf.getMailAuthPassword(); Session session = Session.getDefaultInstance(properties, (mailSmtpAuth.equalsIgnoreCase("true") ? new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(mailAuthUsername, mailAuthPassword); } } : null)); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(mailFrom)); // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(mailTo)); // Set Subject: header field message.setSubject(conf.getMailSubject()); String mailHeaderName = conf.getMailHeaderName(); String mailHeaderValule = conf.getMailHeaderValue(); if (mailHeaderName != null && mailHeaderValule != null) { message.addHeader(mailHeaderName, mailHeaderValule); } String mailMessageText = conf.getMailContentHeader(); message.setText(mailMessageText + "\n\n" + kmlURL); // Send message Transport.send(message); if (LOGGER.isInfoEnabled()) LOGGER.info("Sent message successfully...."); } catch (MessagingException exc) { ActionExceptionHandler.handleError(conf, this, "An error occurrd when sent message ..."); continue; } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error("Send Mail action.execute(): Encountered a NULL event: SKIPPING..."); } continue; } } catch (Exception ioe) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Send Mail action.execute(): Unable to produce the output: ", ioe.getLocalizedMessage(), ioe); } throw new ActionException(this, ioe.getLocalizedMessage(), ioe); } } return ret; }
From source file:it.geosolutions.geobatch.actions.ds2ds.Ds2dsAction.java
/** * Imports data from the source DataStore to the output one * transforming the data as configured.//from ww w . j a v a2s . c o m */ @Override public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { // return object final Queue<EventObject> outputEvents = new LinkedList<EventObject>(); while (events.size() > 0) { final EventObject ev; try { if ((ev = events.remove()) != null) { listenerForwarder.started(); updateTask("Working on incoming event: " + ev.getSource()); Queue<FileSystemEvent> acceptableFiles = acceptableFiles(unpackCompressedFiles(ev)); if (ev instanceof FileSystemEvent && ((FileSystemEvent) ev).getEventType().equals(FileSystemEventType.POLLING_EVENT)) { String fileType = getFileType((FileSystemEvent) ev); EventObject output = null; if ("feature".equalsIgnoreCase(fileType)) { configuration.getOutputFeature().setTypeName( FilenameUtils.getBaseName(((FileSystemEvent) ev).getSource().getName())); output = buildOutputEvent(); updateImportProgress(1, 1, "Completed"); } else { output = importFile((FileSystemEvent) ev); } outputEvents.add(output); } else { if (acceptableFiles.size() == 0) { failAction("No file to process"); } else { List<ActionException> exceptions = new ArrayList<ActionException>(); for (FileSystemEvent fileEvent : acceptableFiles) { try { String fileType = getFileType(fileEvent); EventObject output = null; if ("feature".equalsIgnoreCase(fileType)) { configuration.getOutputFeature().setTypeName(FilenameUtils .getBaseName(((FileSystemEvent) ev).getSource().getName())); output = buildOutputEvent(); updateImportProgress(1, 1, "Completed"); } else { output = importFile(fileEvent); } if (output != null) { // add the event to the return outputEvents.add(output); } else { if (LOGGER.isWarnEnabled()) { LOGGER.warn("No output produced"); } } } catch (ActionException e) { exceptions.add(e); } } if (acceptableFiles.size() == exceptions.size()) { throw new ActionException(this, exceptions.get(0).getMessage()); } else if (exceptions.size() > 0) { if (LOGGER.isWarnEnabled()) { for (ActionException ex : exceptions) { LOGGER.warn("Error in action: " + ex.getMessage()); } } } } } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error("Encountered a NULL event: SKIPPING..."); } continue; } } catch (ActionException ioe) { failAction("Unable to produce the output, " + ioe.getLocalizedMessage(), ioe); } catch (Exception ioe) { failAction("Unable to produce the output: " + ioe.getLocalizedMessage(), ioe); } } return outputEvents; }
From source file:it.geosolutions.geobatch.opensdi.ndvi.NDVIStatsAction.java
/** * Execute process//from w w w. j av a 2 s . c om */ public Queue<EventObject> execute(Queue<EventObject> events) throws ActionException { // return object final Queue<EventObject> ret = new LinkedList<EventObject>(); while (events.size() > 0) { final EventObject ev; try { if ((ev = events.remove()) != null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Working on incoming event: " + ev.getSource()); } if (ev instanceof FileSystemEvent) { FileSystemEvent fileEvent = (FileSystemEvent) ev; File file = fileEvent.getSource(); processXMLFile(file); } // add the event to the return ret.add(ev); } else { if (LOGGER.isErrorEnabled()) { LOGGER.error("Encountered a NULL event: SKIPPING..."); } continue; } } catch (Exception ioe) { final String message = "Unable to produce the output: " + ioe.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, ioe); throw new ActionException(this, message); } } return ret; }