package tk.eclipse.plugin.stepcounter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.ide.IDE;
import tk.stepcounter.CountResult;
import tk.stepcounter.StepCounter;
import tk.stepcounter.StepCounterFactory;
/**
* カウント結果を表示するためのViewPart
*
* @see ViewPart
*/
public class StepCountView extends ViewPart {
private Table table;
private Menu popup;
private MenuItem copy;
private MenuItem selectAll;
private MenuItem clear;
private MenuItem open;
private Clipboard clipboard;
private static String file = StepCounterPlugin.getResourceString("StepCountView.columnName"); //$NON-NLS-1$
private static String type = StepCounterPlugin.getResourceString("StepCountView.columnType"); //$NON-NLS-1$
private static String step = StepCounterPlugin.getResourceString("StepCountView.columnStep"); //$NON-NLS-1$
private static String none = StepCounterPlugin.getResourceString("StepCountView.columnNone"); //$NON-NLS-1$
private static String comment = StepCounterPlugin.getResourceString("StepCountView.columnComment"); //$NON-NLS-1$
private static String total = StepCounterPlugin.getResourceString("StepCountView.columnTotal"); //$NON-NLS-1$
private HashMap files = new HashMap();
/**
* コンストラクタ
*/
public StepCountView() {
super();
}
/**
* ViewPartの中身を作成。
*
* @see ViewPart#createPartControl
*/
public void createPartControl(Composite parent) {
// テーブルを作成
table = new Table(parent,SWT.FULL_SELECTION|SWT.MULTI);
table.setHeaderVisible(true);
table.setLinesVisible(true);
String[] cols = {file,type,step,none,comment,total};
for(int i=0;i<cols.length;i++){
TableColumn col = null;
if(i==0 || i==1){
col = new TableColumn(table,SWT.LEFT);
} else {
col = new TableColumn(table,SWT.RIGHT);
}
col.setText(cols[i]);
if(i==0){
col.setWidth(250);
} else {
col.setWidth(80);
}
col.addSelectionListener(new TableHeaderListener());
}
// クリップボードの準備
clipboard = new Clipboard(parent.getDisplay());
// テーブルにポップアップメニューを追加
popup = new Menu(table.getShell(),SWT.POP_UP);
open = new MenuItem(popup,SWT.PUSH);
open.setText(StepCounterPlugin.getResourceString("StepCountView.menuOpen")); //$NON-NLS-1$
open.addSelectionListener(new TableOpenListener());
copy = new MenuItem(popup,SWT.PUSH);
copy.setText(StepCounterPlugin.getResourceString("StepCountView.menuCopy")); //$NON-NLS-1$
copy.addSelectionListener(new TableCopyListener());
selectAll = new MenuItem(popup,SWT.PUSH);
selectAll.setText(StepCounterPlugin.getResourceString("StepCountView.menuSelectAll")); //$NON-NLS-1$
selectAll.addSelectionListener(new TableSelectAllListener());
new MenuItem(popup,SWT.SEPARATOR);
clear = new MenuItem(popup,SWT.PUSH);
clear.setText(StepCounterPlugin.getResourceString("StepCountView.menuClear")); //$NON-NLS-1$
clear.addSelectionListener(new TableClearListener());
table.addMouseListener(new TableMouseListener());
}
/**
* カウントを実行
*
* @param selection ISelection
*/
public void count(ISelection selection){
// すべて削除
table.removeAll();
files.clear();
if(selection!=null && selection instanceof IStructuredSelection){
IStructuredSelection iSel = (IStructuredSelection)selection;
Iterator ite = iSel.iterator();
long totalStep = 0;
long totalComment = 0;
long totalNone = 0;
while(ite.hasNext()){
Object obj = ite.next();
CountResult result = null;
// Javaソースファイル(JDT)
if(obj instanceof ICompilationUnit){
ICompilationUnit file = (ICompilationUnit)obj;
result = countFile((IFile)file.getResource());
// Javaパッケージ(JDT)
} else if(obj instanceof IPackageFragment){
IPackageFragment pkg = (IPackageFragment)obj;
result = countPackage(pkg);
// ファイル
} else if(obj instanceof IFile){
result = countFile((IFile)obj);
// ディレクトリ
} else if(obj instanceof IFolder){
result = countFolder((IFolder)obj);
}
if(result!=null){
totalStep += result.getStep();
totalNone += result.getNon();
totalComment += result.getComment();
}
}
// 合計行を表示
String[] data = {
total,"", //$NON-NLS-1$
String.valueOf(totalStep),
String.valueOf(totalNone),
String.valueOf(totalComment),
String.valueOf(totalStep+totalNone+totalComment)
};
TableItem item = new TableItem(table,SWT.NULL);
item.setText(data);
}
}
/**
* 1ファイルをカウント
*
* @param file ファイル
* @return このファイルのカウント結果
*/
private CountResult countFile(IFile file){
try {
StepCounter counter = StepCounterFactory.getCounter(file.getName());
// 対応するカウンタが存在する場合
if(counter!=null){
CountResult result = counter.count(file.getLocation().makeAbsolute().toFile());
String type = result.getFileType();
long comment = result.getComment();
long none = result.getNon();
long step = result.getStep();
String[] data = {
file.getFullPath().toString(),
//file.getName(),
type,
String.valueOf(step),
String.valueOf(none),
String.valueOf(comment),
String.valueOf(step+none+comment)
};
TableItem item = new TableItem(table,SWT.NULL);
item.setText(data);
files.put(file.getFullPath().toString(),file);
return result;
// 対応するカウンタが存在しない場合
} else {
String[] data = {
file.getFullPath().toString(),
//file.getName(),
StepCounterPlugin.getResourceString("StepCountView.notSupported"), //$NON-NLS-1$
"", //$NON-NLS-1$
"", //$NON-NLS-1$
"", //$NON-NLS-1$
"" //$NON-NLS-1$
};
TableItem item = new TableItem(table,SWT.NULL);
item.setText(data);
files.put(file.getFullPath().toString(),file);
return null;
}
} catch(Exception ex){
ex.printStackTrace();
return null;
}
}
/**
* フォルダをカウント
*
* @param folder フォルダ
* @return フォルダ内のカウント合計
*/
private CountResult countFolder(IFolder folder){
CountResult result = new CountResult();
try {
IResource[] children = folder.members();
for(int i=0;i<children.length;i++){
if(children[i] instanceof IFile){
CountResult count = countFile((IFile)children[i]);
if(count!=null){
result.setStep (result.getStep() + count.getStep());
result.setNon (result.getNon() + count.getNon());
result.setComment(result.getComment() + count.getComment());
}
} else if(children[i] instanceof IFolder){
CountResult count = countFolder((IFolder)chi
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
tk.eclipse.plugin.stepcounter.rar (31个子文件)
tk.eclipse.plugin.stepcounter
stepcounter.jar 39KB
icons
stepcounter.gif 983B
.project 690B
plugin_ja.properties 320B
plugin.properties 151B
.template 1KB
src
tk
eclipse
plugin
stepcounter
StepCountAction.java 2KB
StepCounterPluginResources.properties 432B
StepCounterPluginResources_ja.properties 628B
StepCounterPlugin.java 1KB
StepCountView.java 15KB
stepcounter
DefaultStepCounter.java 4KB
Main.java 3KB
StepCounterFactory.java 8KB
CountResult.java 2KB
Util.java 2KB
AreaComment.java 1KB
format
FormatterFactory.java 625B
DefaultFormatter.java 3KB
CSVFormatter.java 1KB
ResultFormatter.java 638B
StepCounter.java 212B
gui
ConfigManager.java 3KB
MainWindowListener.java 532B
StringUtility.java 7KB
MainWindow.java 6KB
ant
StepCounterTask.java 3KB
.classpath 301B
plugin.xml 3KB
build.xml 737B
build.properties 112B
共 31 条
- 1
资源评论
水草会武
- 粉丝: 44
- 资源: 67
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- yolov5,SSD 可能使用到的一些代码
- 介绍离散性制造行业的MES系统流程
- 基于IDEA-CCNL/Randeng-Pegasus-238M-Summary-Chines微调的中文文本摘要任务源码+数据集
- 微信小程序源码 车源宝 二手车交易平台 源码下载
- 微信小程序源码 实现 城市切换 demo 根据城市首字母排序城市 选择城市 源码下载
- 2024新版计算机编译原理期末速成全套视频教程(视频+配套资料)
- VMware7.0虚拟机硬盘无法编辑,无法连接到Profile-Driven Storage Service
- arm64内核的mongo镜像
- 基于stm32f103c单片机+MPU6050+0.96英寸OLED显示屏双柄遥控器硬件(原理图+PCB)工程文件.zip
- 整理的关于少儿编程的学习路径,以及如何在小升初,初升高和大学充分的利用起来编程经验的优势
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功