• R/O
  • SSH
  • HTTPS

treespy: Commit


Commit MetaInfo

Revisão30 (tree)
Hora2010-11-15 21:08:49
Autorhiyamax

Mensagem de Log

ファイル名でのフィルター機能を実装(とりあえず版)

Mudança Sumário

Diff

--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/popup/actions/DuplicationSpyAction.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/popup/actions/DuplicationSpyAction.java (revision 30)
@@ -18,7 +18,7 @@
1818 import com.pgdist.treespy.ui.SpyArg;
1919 import com.pgdist.treespy.ui.jobs.DuplicationSpyJob;
2020 import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory;
21-import com.pgdist.treespy.ui.wizards.TreeSpyWizard;
21+import com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard;
2222
2323 /**
2424 * DuplicationSpyAction
@@ -49,7 +49,7 @@
4949 };
5050
5151 // ウィザード起動
52- Wizard wizard = new TreeSpyWizard<IContainer>(arg) {
52+ Wizard wizard = new DefaultTreeSpyWizard<IContainer>(arg) {
5353
5454 @Override
5555 protected TreeSpyJobFactory<IContainer> createTreeSpyJobFactory() {
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/popup/actions/ExtensionSpyAction.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/popup/actions/ExtensionSpyAction.java (revision 30)
@@ -18,7 +18,7 @@
1818 import com.pgdist.treespy.ui.SpyArg;
1919 import com.pgdist.treespy.ui.jobs.ExtensionSpyJob;
2020 import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory;
21-import com.pgdist.treespy.ui.wizards.TreeSpyWizard;
21+import com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard;
2222
2323 /**
2424 * ExtensionSpyAction
@@ -49,7 +49,7 @@
4949 };
5050
5151 // ウィザード起動
52- Wizard wizard = new TreeSpyWizard<IContainer>(arg) {
52+ Wizard wizard = new DefaultTreeSpyWizard<IContainer>(arg) {
5353
5454 @Override
5555 protected TreeSpyJobFactory<IContainer> createTreeSpyJobFactory() {
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/popup/actions/JavaTreeSpyAction.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/popup/actions/JavaTreeSpyAction.java (revision 30)
@@ -19,7 +19,7 @@
1919 import com.pgdist.treespy.ui.SpyArg;
2020 import com.pgdist.treespy.ui.jobs.JavaTreeSpyJob;
2121 import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory;
22-import com.pgdist.treespy.ui.wizards.TreeSpyWizard;
22+import com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard;
2323
2424 /**
2525 * JavaTreeSpyAction
@@ -50,7 +50,7 @@
5050 };
5151
5252 // ウィザード起動
53- Wizard wizard = new TreeSpyWizard<IParent>(arg) {
53+ Wizard wizard = new DefaultTreeSpyWizard<IParent>(arg) {
5454
5555 @Override
5656 protected TreeSpyJobFactory<IParent> createTreeSpyJobFactory() {
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/wizards/MatchingRuleInputPage.java (nonexistent)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/wizards/MatchingRuleInputPage.java (revision 30)
@@ -0,0 +1,45 @@
1+/*
2+ * Copyright (c) 2010 PROPAGANDIST Inc.
3+ * All rights reserved. This program and the accompanying materials
4+ * are made available under the terms of the Eclipse Public License v1.0
5+ * which accompanies this distribution, and is available at
6+ * http://www.eclipse.org/legal/epl-v10.html
7+ */
8+package com.pgdist.treespy.ui.wizards;
9+
10+import org.eclipse.jface.wizard.WizardPage;
11+import org.eclipse.swt.SWT;
12+import org.eclipse.swt.layout.GridData;
13+import org.eclipse.swt.layout.GridLayout;
14+import org.eclipse.swt.widgets.Composite;
15+import org.eclipse.swt.widgets.Text;
16+
17+/**
18+ * MatchingRuleInputPage
19+ *
20+ * @author hiyama@propagandist.co.jp
21+ * @since 2010/11/12
22+ */
23+public class MatchingRuleInputPage extends WizardPage {
24+
25+ Text rules;
26+
27+ protected MatchingRuleInputPage(String pageName) {
28+ super(pageName);
29+ setDescription("ファイル名のマッチング・ルールを正規表現で入力してください。\n複数指定する場合は改行で区切ってください。");
30+ setPageComplete(true);
31+ }
32+
33+ /* (non-Javadoc)
34+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
35+ */
36+ public void createControl(Composite parent) {
37+ Composite composite = new Composite(parent, SWT.NULL);
38+ composite.setLayout(new GridLayout());
39+ setControl(composite);
40+
41+ rules = new Text(composite, SWT.BORDER | SWT.MULTI);
42+ rules.setLayoutData(new GridData(GridData.FILL_BOTH));
43+ }
44+
45+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/wizards/DefaultTreeSpyWizard.java (nonexistent)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/wizards/DefaultTreeSpyWizard.java (revision 30)
@@ -0,0 +1,95 @@
1+/*
2+ * Copyright (c) 2010 PROPAGANDIST Inc.
3+ * All rights reserved. This program and the accompanying materials
4+ * are made available under the terms of the Eclipse Public License v1.0
5+ * which accompanies this distribution, and is available at
6+ * http://www.eclipse.org/legal/epl-v10.html
7+ */
8+package com.pgdist.treespy.ui.wizards;
9+
10+import org.eclipse.jface.wizard.Wizard;
11+
12+import com.pgdist.treespy.ui.SpyArg;
13+import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory;
14+import com.pgdist.treespy.ui.jobs.TreeSpyJobLauncher;
15+
16+/**
17+ * TreeSpyWizard
18+ *
19+ * @author hiyama@propagandist.co.jp
20+ * @since 2010/09/27
21+ */
22+public abstract class DefaultTreeSpyWizard<T> extends Wizard {
23+
24+ /** 処理対象のコンテナの配列 */
25+ protected SpyArg<T> arg;
26+
27+ /** 出力形式選択ウィザード・ページ */
28+ OutputStyleSelectionPage ossPage;
29+
30+ public DefaultTreeSpyWizard(SpyArg<T> arg) {
31+ this.arg = arg;
32+ setWindowTitle(arg.getName());
33+ }
34+
35+ /**
36+ * {@inheritDoc}
37+ */
38+ @Override
39+ public void addPages() {
40+ ossPage = new OutputStyleSelectionPage("ossPage");
41+ addPage(ossPage);
42+ }
43+
44+ /**
45+ * {@inheritDoc}
46+ */
47+ @Override
48+ public boolean canFinish() {
49+ return ossPage.isPageComplete();
50+ }
51+
52+ /**
53+ * {@inheritDoc}
54+ */
55+ @Override
56+ public boolean performFinish() {
57+
58+ // 入力の反映
59+ applyArg(arg);
60+
61+ // ジョブ・ランチャーの準備
62+ TreeSpyJobLauncher<T> launcher = null;
63+ switch (ossPage.style) {
64+ case Clipboard:
65+ launcher = TreeSpyJobLauncher.toClipboard(arg);
66+ break;
67+ case Excel:
68+ launcher = TreeSpyJobLauncher.toExcelFile(arg, ossPage.file.getText(), ossPage.open.getSelection());
69+ break;
70+ case Text:
71+ launcher = TreeSpyJobLauncher.toTextFile(arg, ossPage.file.getText(), ossPage.open.getSelection());
72+ break;
73+ }
74+ launcher.setShell(getShell());
75+
76+ // ジョブのスケジュール登録
77+ return launcher.schedule(createTreeSpyJobFactory());
78+ }
79+
80+ /**
81+ * ウィザードの入力を反映する。
82+ * @param arg 引数オブジェクト
83+ */
84+ protected void applyArg(SpyArg<T> arg) {
85+ // 出力形式
86+ arg.setOutputStyle(ossPage.style);
87+ }
88+
89+ /**
90+ * ジョブのファクトリーオブジェクトを生成します。
91+ * @return ファクトリーオブジェクト
92+ */
93+ protected abstract TreeSpyJobFactory<T> createTreeSpyJobFactory();
94+
95+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/wizards/TreeSpyWizard.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/wizards/TreeSpyWizard.java (revision 30)
@@ -7,80 +7,93 @@
77 */
88 package com.pgdist.treespy.ui.wizards;
99
10-import org.eclipse.jface.wizard.Wizard;
10+import java.util.ArrayList;
11+import java.util.List;
12+import java.util.regex.Pattern;
13+import java.util.regex.PatternSyntaxException;
1114
15+import org.eclipse.core.runtime.IStatus;
16+import org.eclipse.core.runtime.Status;
17+import org.eclipse.jface.dialogs.ErrorDialog;
18+
19+import com.pgdist.treespy.TreeSpyPlugin;
20+import com.pgdist.treespy.core.util.Lang;
1221 import com.pgdist.treespy.ui.SpyArg;
13-import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory;
14-import com.pgdist.treespy.ui.jobs.TreeSpyJobLauncher;
1522
1623 /**
1724 * TreeSpyWizard
1825 *
19- * @author hiyama@propagandist.co.jp
20- * @since 2010/09/27
26+ * @author hiyama.suguru
27+ * @since 2010/11/12
2128 */
22-public abstract class TreeSpyWizard<T> extends Wizard {
29+public abstract class TreeSpyWizard<T> extends DefaultTreeSpyWizard<T> {
2330
24- /** 処理対象のコンテナの配列 */
25- private SpyArg<T> arg;
31+ MatchingRuleInputPage mriPage;
2632
27- /** 出力形式選択ウィザード・ページ */
28- OutputStyleSelectionPage page1;
29-
3033 public TreeSpyWizard(SpyArg<T> arg) {
31- this.arg = arg;
32- setWindowTitle(arg.getName());
34+ super(arg);
3335 }
3436
35- /**
36- * {@inheritDoc}
37+ /* (non-Javadoc)
38+ * @see com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard#addPages()
3739 */
3840 @Override
3941 public void addPages() {
40- page1 = new OutputStyleSelectionPage("page1");
41- addPage(page1);
42- }
42+ // 親クラスのページを追加
43+ super.addPages();
4344
44- /**
45- * {@inheritDoc}
46- */
47- @Override
48- public boolean canFinish() {
49- return page1.isPageComplete();
45+ mriPage = new MatchingRuleInputPage("mriPage");
46+ addPage(mriPage);
5047 }
5148
52- /**
53- * {@inheritDoc}
49+ /* (non-Javadoc)
50+ * @see com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard#performFinish()
5451 */
5552 @Override
5653 public boolean performFinish() {
54+ try {
55+ // 正規表現の妥当性を検証
56+ toPattern();
57+ } catch (PatternSyntaxException e) {
58+ IStatus status = new Status(IStatus.ERROR, TreeSpyPlugin.PLUGIN_ID, "正規表現に誤りがあります。", e);
59+ // ログ
60+ TreeSpyPlugin.getDefault().getLog().log(status);
61+ // エラーダイアログ
62+ ErrorDialog.openError(getShell(), arg.getName(), "エラーが発生しました。", status);
5763
58- // 出力形式
59- arg.setOutputStyle(page1.style);
60-
61- // ジョブ・ランチャーの準備
62- TreeSpyJobLauncher<T> launcher = null;
63- switch (page1.style) {
64- case Clipboard:
65- launcher = TreeSpyJobLauncher.toClipboard(arg);
66- break;
67- case Excel:
68- launcher = TreeSpyJobLauncher.toExcelFile(arg, page1.file.getText(), page1.open.getSelection());
69- break;
70- case Text:
71- launcher = TreeSpyJobLauncher.toTextFile(arg, page1.file.getText(), page1.open.getSelection());
72- break;
64+ return false;
7365 }
74- launcher.setShell(getShell());
7566
76- // ジョブのスケジュール登録
77- return launcher.schedule(createTreeSpyJobFactory());
67+ return super.performFinish();
7868 }
7969
8070 /**
81- * ジョブのファクトリーオブジェクトを生成します。
82- * @return ファクトリーオブジェクト
71+ * 入力された文字列を正規表現パターンの配列に変換します。
72+ * @return 正規表現パターンの配列
8373 */
84- protected abstract TreeSpyJobFactory<T> createTreeSpyJobFactory();
74+ private Pattern[] toPattern() {
75+ List<Pattern> matchingRules = new ArrayList<Pattern>();
76+ for (String rule : mriPage.rules.getText().split("(\r|\n)+")) {
77+ if (Lang.isNotEmpty(rule)) {
78+ matchingRules.add(Pattern.compile(rule));
79+ }
80+ }
81+ if (!matchingRules.isEmpty()) {
82+ return matchingRules.toArray(new Pattern[matchingRules.size()]);
83+ }
84+ return null;
85+ }
8586
87+ /* (non-Javadoc)
88+ * @see com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard#applyArg(com.pgdist.treespy.ui.SpyArg)
89+ */
90+ @Override
91+ protected void applyArg(SpyArg<T> arg) {
92+ super.applyArg(arg);
93+
94+ // マッチング・ルールの反映
95+ Pattern[] matchingRules = toPattern();
96+ arg.setMatchingRules(matchingRules);
97+ }
98+
8699 }
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/SpyArg.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/SpyArg.java (revision 30)
@@ -7,6 +7,9 @@
77 */
88 package com.pgdist.treespy.ui;
99
10+import java.util.regex.Matcher;
11+import java.util.regex.Pattern;
12+
1013 import com.pgdist.treespy.OutputStyle;
1114
1215 /**
@@ -17,10 +20,24 @@
1720 */
1821 public abstract class SpyArg<T> {
1922
23+ /**
24+ * 処理名称
25+ */
2026 private String name;
2127
28+ /**
29+ * 処理対象リソース
30+ */
2231 private T[] targets;
2332
33+ /**
34+ * マッチング・ルールの配列
35+ */
36+ private Pattern[] matchingRules;
37+
38+ /**
39+ * 出力形式
40+ */
2441 private OutputStyle outputStyle;
2542
2643 public SpyArg(String name, T[] targets) {
@@ -52,6 +69,34 @@
5269 this.outputStyle = outputStyle;
5370 }
5471
72+ public Pattern[] getMatchingRules() {
73+ return matchingRules;
74+ }
75+
76+ public void setMatchingRules(Pattern[] matchingRules) {
77+ this.matchingRules = matchingRules;
78+ }
79+
80+ /**
81+ * 指定されたファイル名がマッチング・ルールに一致するか判定します。
82+ * マッチング・ルールが未設定の場合は true を返却します。
83+ * @param filename ファイル名
84+ * @return いずれかのマッチング・ルールに一致する場合に true
85+ */
86+ public boolean match(String filename) {
87+ if (getMatchingRules() != null) {
88+ for (Pattern pattern : getMatchingRules()) {
89+ Matcher m = pattern.matcher(filename);
90+ if (m.matches()) {
91+ return true;
92+ }
93+ }
94+ return false;
95+ }
96+ // 未設定の場合は true
97+ return true;
98+ }
99+
55100 public abstract String toString(T target);
56101
57102 }
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/jobs/TreeSpyJob.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/jobs/TreeSpyJob.java (revision 30)
@@ -79,9 +79,12 @@
7979 // 要素管理に登録
8080 folders.put(resource.getFullPath(), node);
8181 } else if (resource instanceof IFile) {
82- // ファイル要素
83- FileNode node = new FileNodeImpl((IFile) resource);
84- parent.addChild(node);
82+ IFile file = (IFile) resource;
83+ if (arg.match(file.getName())) {
84+ // ファイル要素
85+ FileNode node = new FileNodeImpl(file);
86+ parent.addChild(node);
87+ }
8588 } else {
8689 // 取り扱い不明なリソース
8790 String msg = String.format(
--- trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/jobs/AbstractTreeSpyJob.java (revision 29)
+++ trunk/com.pgdist.treespy/src/com/pgdist/treespy/ui/jobs/AbstractTreeSpyJob.java (revision 30)
@@ -34,7 +34,10 @@
3434
3535 private TreeWriter writer;
3636
37- private SpyArg<T> arg;
37+ /**
38+ * パラメータ
39+ */
40+ protected SpyArg<T> arg;
3841
3942 public AbstractTreeSpyJob(Display display, String name, TreeWriter writer, SpyArg<T> arg) {
4043 super(display, name);
Show on old repository browser