gpt4 book ai didi

java - 定期检查文件状态是否更改 RCP

转载 作者:太空宇宙 更新时间:2023-11-04 15:08:58 25 4
gpt4 key购买 nike

定期检查 XML 文件中的书籍状态的方法的概念是什么,如果状态发生变化,它将通过 RCP 发出警报?我想创建可以执行此操作的任务。我在 JFrame 中有主类。

这是 XmlFile 和 POJO。

 package net.kxyz;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import xyz.libary.Book;
import xyz.libary.DataInterface;

/**
*
* @author kuman
*/
public class XmlDataInterfaceImpl implements DataInterface {

File fXmlFile = new File("baza.xml");
ArrayList<Book> book = new ArrayList<>();

@Override
public void updateBook(Book book2) {

int index = book2.getId();
this.book.get(index).setTitle(book2.getTitle());
this.book.get(index).setAuthor(book2.getAuthor());
this.book.get(index).setYear(book2.getYear());
this.book.get(index).setState(book2.isState());

}

@Override
public ArrayList<Book> getAllBooks() {
//code
return book;
}

public void addBook(Book book2) {
//code
}

@Override
public void deleteBook(Book book) {
//code
}

private void toFile() {

//code

}

}

POJO

 /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package xyz.libary;

/**
*
* @author kuman
*/
public class Book {
int id;
String title;
String author;
int year;
Boolean state;

public Book() {};
public Book(int id, String title, String author, int year) {
this.id = id ;
this.title = title;
this.author = author;
this.year = year;
this.state = true;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}


public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public Boolean isState() {
return state;
}

public void setState(Boolean state) {
this.state = state;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public void setState(Object value) {
this.state=(Boolean)(value);
}



}

最佳答案

您可以创建一个在 xyz 时间后重复的作业。

final Job job = new Job("Name")
{

@Override
protected IStatus run( final IProgressMonitor monitor )
{
// do something
schedule( delay ) // schedule again after "delay" mili seconds
return status;
}
};
job.schedule();

参见https://www.eclipse.org/articles/Article-Concurrency/jobs-api.html

http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcore%2Fruntime%2Fjobs%2FJob.html

关于java - 定期检查文件状态是否更改 RCP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21580564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com