package popmenu.popup.actions;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import popmenu.entity.Info;
public class NewAction implements IObjectActionDelegate {
public Shell shell;
public static IProject selected;
public static List<String> FILE_PATH;
public static List<String> CLASS_PATH;
public int curryIndex= 0 ;
public TableViewer tableViewer;
public String[] str;
/**
* Constructor for Action1.
*/
public NewAction() {
super();
}
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}
public void showMess(String msg){
MessageDialog.openInformation(
shell,
"Popmenu",
msg);
}
/**
* @see IActionDelegate#run(IAction)
*/
@SuppressWarnings("static-access")
public void run(IAction action) {
CreateXml();
Display display= Display.getCurrent();
shell= new Shell(display);
shell.setText("SpringMVC 管理");
shell.setSize(600, 500);
shell.setBackground(new Color(display, 255, 251, 240));
GridLayout layout = new GridLayout(4, false);
shell.setLayout(layout);
center(display, shell);
str=getAllProjectName();
Label title = new Label(shell, SWT.CENTER);
title.setText("SpringMVC Controller Manager");
title.setSize(60, 200);
GridData titleData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
titleData.horizontalSpan=4;
title.setLayoutData(titleData);
Label selectText = new Label(shell, SWT.LEFT);
selectText.setText("项目列表:");
selectText.setSize(40, 70);
GridData selectTexGrid=new GridData();
selectTexGrid.horizontalSpan=1;
selectText.setLayoutData(selectTexGrid);
Combo proSelect = new Combo(shell, SWT.NONE);
proSelect.setItems(str);
curryIndex=getCurrProjectIndex(str, this.selected.getName());
proSelect.select(curryIndex);
proSelect.setSize(500, 70);
GridData proSelectGrid = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
proSelectGrid.horizontalSpan=1;
proSelect.setLayoutData(proSelectGrid);
proSelect.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event arg0) {
curryIndex=((Combo)arg0.widget).getSelectionIndex();
tableViewer.setInput(getCurryInfo(str[curryIndex]));
}
});
GridData buttonGrid= new GridData(GridData.FILL_HORIZONTAL);
buttonGrid.horizontalSpan=1;
Button flushButton = new Button(shell, SWT.NONE);
flushButton.setText("刷新");
flushButton.setLayoutData(buttonGrid);
flushButton.addListener(SWT.MouseDown,new Listener() {
public void handleEvent(Event paramEvent) {
CreateXml();
tableViewer.refresh();
tableViewer.setInput(getCurryInfo(str[curryIndex]));
}
});
/*Button saveButton = new Button(shell, SWT.NONE);
saveButton.setText("保存");
saveButton.setLayoutData(buttonGrid);
saveButton.addListener(SWT.MouseDown,new Listener() {
public void handleEvent(Event paramEvent) {
List alis= (List) tableViewer.getInput();
System.out.println(alis.get(0));
}
});*/
tableViewer = new TableViewer(shell, SWT.MULTI | SWT.FULL_SELECTION |
SWT.BORDER|SWT.V_SCROLL|SWT.H_SCROLL);
Table table= tableViewer.getTable();
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.setBounds(97, 79, 600, 400);
GridData tableGrid = new GridData(GridData.FILL_BOTH);
tableGrid.horizontalSpan=4;
table.setLayoutData(tableGrid);
final TableColumn newColumnTableColumn = new TableColumn(table, SWT.NONE);
newColumnTableColumn.setWidth(200);
newColumnTableColumn.setText("package");
final TableColumn newColumnTableColumn_1 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_1.setWidth(100);
newColumnTableColumn_1.setText("ClassName");
final TableColumn newColumnTableColumn_2 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_2.setWidth(100);
newColumnTableColumn_2.setText("Method");
final TableColumn newColumnTableColumn_3 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_3.setWidth(100);
newColumnTableColumn_3.setText("url");
final TableColumn newColumnTableColumn_4 = new TableColumn(table, SWT.NONE);
newColumnTableColumn_4.setWidth(100);
newColumnTableColumn_4.setText("returnType");
tableViewer.setContentProvider(new ContentProvider());
tableViewer.setLabelProvider(new TableLabelProvider());
tableViewer.setInput(getCurryInfo(str[curryIndex]));
tableViewer.setColumnProperties(new String[]{"package","ClassName","Method","url","returnType"});
CellEditor[] cellEditor = new CellEditor[5];
cellEditor[0] = new TextCellEditor(tableViewer.getTable());
cellEditor[1] = new TextCellEditor(tableViewer.getTable());
cellEditor[2] = new TextCellEditor(tableViewer.getTable());
cellEditor[3] = new TextCellEditor(tableViewer.getTable());
cellEditor[4] = new TextCellEditor(tableViewer.getTable());
tableViewer.setCellEditors(cellEditor);
ICellModifier modifier = new MyCellModifier(tableViewer);
tableViewer.setCellModifier(modifier);
// shell.pack();
shell.open();
/* while(!shell.isDisposed( )){
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();*/
}
/**
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
@SuppressWarnings("static-access")
public void selectionChanged(IAction action, ISelection selection) {
IProject project = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
project= ((IRe