Pessoal, consegui ter algum progresso durante esse tempo, mas tenho bastantes dificuldades ainda. Vamos as minhas dúvidas.
Alguém pode dar uma olha nesse código, e me responder se ta tudo ok com ele, só pra saber se eu realmente implementei corretamente essas funcionalidades:
package com.sodr.gwt.rpc.server;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.sodr.gwt.rpc.client.MyService;
public class MyServiceImpl extends RemoteServiceServlet implements MyService {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public String greeting(String helloTo) {
return "Hello "+helloTo+"from " + getServletContext().getServerInfo();
}
@Override
public String criarArquivo(String arquivo) {
String text = "Write your text here";
FileWriter file;
try {
file = new FileWriter(new File("File.txt"));
file.write(text);
file.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public String lerArquivo(File arquivo) {
StringBuffer fs = new StringBuffer();
try
{
BufferedReader in = new BufferedReader(new FileReader("Exemplo.txt"));
String str;
while (in.ready())
{
str = in.readLine();
fs.append(str);
System.out.println(str);
}
in.close();
}
catch (IOException e)
{
System.out.println("Arquivo nao encontrado");
}
return null;
}
@Override
public String copiaArquivo(File prim, File segund) {
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(null);
File arquivoc = jfc.getSelectedFile();
JOptionPane.showMessageDialog(null,"Selecione o diretorio de destino");
jfc.showOpenDialog(null);
arquivoc.renameTo(new File(jfc.getCurrentDirectory().getAbsolutePath(), arquivoc.getName()));
return null;
}
@Override
public String deletaArquivo(File arquivo) {
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(null);
File arquivod = jfc.getSelectedFile();
StringBuffer fs = new StringBuffer();
try
{
BufferedReader in = new BufferedReader(new FileReader(arquivod));
String str;
while (in.ready())
{
str = in.readLine();
fs.append(str);
System.out.println(str);
}
in.close();
}
catch (IOException e)
{
System.out.println("Arquivo nao encontrado");
}
arquivod.delete();
return null;
}
}
E, nesse outro código, minha dúvida é sobre a criação do objeto proxy. Aque eu criei um objeto proxy para um dos métodos, eu devo repetir esse processo para todos os outros métodos?
package com.sodr.gwt.rpc.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class MyRpcDemo implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Button button = new Button("Click me");
final Label label = new Label();
button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if (label.getText().equals(""))
remoteGreeting(label);
else
label.setText("");
}
private void remoteGreeting(final Label label) {
MyServiceAsync greetingService = (MyServiceAsync) GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) greetingService;
String moduleRelativeURL = GWT.getModuleBaseURL()+"greeting";
endpoint.setServiceEntryPoint(moduleRelativeURL);
AsyncCallback callback = new AsyncCallback(){
public void onFailure(Throwable caught) {
// TODO handle errors
}
public void onSuccess(Object result) {
label.setText((String) result);
}
};
greetingService.greeting("GWT-client", callback);
}
});
// Assume that the host HTML has elements defined whose
// IDs are "slot1", "slot2". In a real app, you probably would not want
// to hard-code IDs. Instead, you could, for example, search for all
// elements with a particular CSS class and replace them with widgets.
//
RootPanel.get("slot1").add(button);
RootPanel.get("slot2").add(label);
}
}
E por último, alguém pode me explicar como eu instalo o Gwt-Eclipse Plugin, e explicar por cima como eu crio interfaces com eles. Agradeo desde ja por qualquer ajuda.