ファイル名でのフィルター機能を実装(とりあえず版)
@@ -18,7 +18,7 @@ | ||
18 | 18 | import com.pgdist.treespy.ui.SpyArg; |
19 | 19 | import com.pgdist.treespy.ui.jobs.DuplicationSpyJob; |
20 | 20 | import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory; |
21 | -import com.pgdist.treespy.ui.wizards.TreeSpyWizard; | |
21 | +import com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard; | |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * DuplicationSpyAction |
@@ -49,7 +49,7 @@ | ||
49 | 49 | }; |
50 | 50 | |
51 | 51 | // ウィザード起動 |
52 | - Wizard wizard = new TreeSpyWizard<IContainer>(arg) { | |
52 | + Wizard wizard = new DefaultTreeSpyWizard<IContainer>(arg) { | |
53 | 53 | |
54 | 54 | @Override |
55 | 55 | protected TreeSpyJobFactory<IContainer> createTreeSpyJobFactory() { |
@@ -18,7 +18,7 @@ | ||
18 | 18 | import com.pgdist.treespy.ui.SpyArg; |
19 | 19 | import com.pgdist.treespy.ui.jobs.ExtensionSpyJob; |
20 | 20 | import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory; |
21 | -import com.pgdist.treespy.ui.wizards.TreeSpyWizard; | |
21 | +import com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard; | |
22 | 22 | |
23 | 23 | /** |
24 | 24 | * ExtensionSpyAction |
@@ -49,7 +49,7 @@ | ||
49 | 49 | }; |
50 | 50 | |
51 | 51 | // ウィザード起動 |
52 | - Wizard wizard = new TreeSpyWizard<IContainer>(arg) { | |
52 | + Wizard wizard = new DefaultTreeSpyWizard<IContainer>(arg) { | |
53 | 53 | |
54 | 54 | @Override |
55 | 55 | protected TreeSpyJobFactory<IContainer> createTreeSpyJobFactory() { |
@@ -19,7 +19,7 @@ | ||
19 | 19 | import com.pgdist.treespy.ui.SpyArg; |
20 | 20 | import com.pgdist.treespy.ui.jobs.JavaTreeSpyJob; |
21 | 21 | import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory; |
22 | -import com.pgdist.treespy.ui.wizards.TreeSpyWizard; | |
22 | +import com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard; | |
23 | 23 | |
24 | 24 | /** |
25 | 25 | * JavaTreeSpyAction |
@@ -50,7 +50,7 @@ | ||
50 | 50 | }; |
51 | 51 | |
52 | 52 | // ウィザード起動 |
53 | - Wizard wizard = new TreeSpyWizard<IParent>(arg) { | |
53 | + Wizard wizard = new DefaultTreeSpyWizard<IParent>(arg) { | |
54 | 54 | |
55 | 55 | @Override |
56 | 56 | protected TreeSpyJobFactory<IParent> createTreeSpyJobFactory() { |
@@ -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 | +} |
@@ -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 | +} |
@@ -7,80 +7,93 @@ | ||
7 | 7 | */ |
8 | 8 | package com.pgdist.treespy.ui.wizards; |
9 | 9 | |
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; | |
11 | 14 | |
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; | |
12 | 21 | import com.pgdist.treespy.ui.SpyArg; |
13 | -import com.pgdist.treespy.ui.jobs.TreeSpyJobFactory; | |
14 | -import com.pgdist.treespy.ui.jobs.TreeSpyJobLauncher; | |
15 | 22 | |
16 | 23 | /** |
17 | 24 | * TreeSpyWizard |
18 | 25 | * |
19 | - * @author hiyama@propagandist.co.jp | |
20 | - * @since 2010/09/27 | |
26 | + * @author hiyama.suguru | |
27 | + * @since 2010/11/12 | |
21 | 28 | */ |
22 | -public abstract class TreeSpyWizard<T> extends Wizard { | |
29 | +public abstract class TreeSpyWizard<T> extends DefaultTreeSpyWizard<T> { | |
23 | 30 | |
24 | - /** 処理対象のコンテナの配列 */ | |
25 | - private SpyArg<T> arg; | |
31 | + MatchingRuleInputPage mriPage; | |
26 | 32 | |
27 | - /** 出力形式選択ウィザード・ページ */ | |
28 | - OutputStyleSelectionPage page1; | |
29 | - | |
30 | 33 | public TreeSpyWizard(SpyArg<T> arg) { |
31 | - this.arg = arg; | |
32 | - setWindowTitle(arg.getName()); | |
34 | + super(arg); | |
33 | 35 | } |
34 | 36 | |
35 | - /** | |
36 | - * {@inheritDoc} | |
37 | + /* (non-Javadoc) | |
38 | + * @see com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard#addPages() | |
37 | 39 | */ |
38 | 40 | @Override |
39 | 41 | public void addPages() { |
40 | - page1 = new OutputStyleSelectionPage("page1"); | |
41 | - addPage(page1); | |
42 | - } | |
42 | + // 親クラスのページを追加 | |
43 | + super.addPages(); | |
43 | 44 | |
44 | - /** | |
45 | - * {@inheritDoc} | |
46 | - */ | |
47 | - @Override | |
48 | - public boolean canFinish() { | |
49 | - return page1.isPageComplete(); | |
45 | + mriPage = new MatchingRuleInputPage("mriPage"); | |
46 | + addPage(mriPage); | |
50 | 47 | } |
51 | 48 | |
52 | - /** | |
53 | - * {@inheritDoc} | |
49 | + /* (non-Javadoc) | |
50 | + * @see com.pgdist.treespy.ui.wizards.DefaultTreeSpyWizard#performFinish() | |
54 | 51 | */ |
55 | 52 | @Override |
56 | 53 | 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); | |
57 | 63 | |
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; | |
73 | 65 | } |
74 | - launcher.setShell(getShell()); | |
75 | 66 | |
76 | - // ジョブのスケジュール登録 | |
77 | - return launcher.schedule(createTreeSpyJobFactory()); | |
67 | + return super.performFinish(); | |
78 | 68 | } |
79 | 69 | |
80 | 70 | /** |
81 | - * ジョブのファクトリーオブジェクトを生成します。 | |
82 | - * @return ファクトリーオブジェクト | |
71 | + * 入力された文字列を正規表現パターンの配列に変換します。 | |
72 | + * @return 正規表現パターンの配列 | |
83 | 73 | */ |
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 | + } | |
85 | 86 | |
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 | + | |
86 | 99 | } |
@@ -7,6 +7,9 @@ | ||
7 | 7 | */ |
8 | 8 | package com.pgdist.treespy.ui; |
9 | 9 | |
10 | +import java.util.regex.Matcher; | |
11 | +import java.util.regex.Pattern; | |
12 | + | |
10 | 13 | import com.pgdist.treespy.OutputStyle; |
11 | 14 | |
12 | 15 | /** |
@@ -17,10 +20,24 @@ | ||
17 | 20 | */ |
18 | 21 | public abstract class SpyArg<T> { |
19 | 22 | |
23 | + /** | |
24 | + * 処理名称 | |
25 | + */ | |
20 | 26 | private String name; |
21 | 27 | |
28 | + /** | |
29 | + * 処理対象リソース | |
30 | + */ | |
22 | 31 | private T[] targets; |
23 | 32 | |
33 | + /** | |
34 | + * マッチング・ルールの配列 | |
35 | + */ | |
36 | + private Pattern[] matchingRules; | |
37 | + | |
38 | + /** | |
39 | + * 出力形式 | |
40 | + */ | |
24 | 41 | private OutputStyle outputStyle; |
25 | 42 | |
26 | 43 | public SpyArg(String name, T[] targets) { |
@@ -52,6 +69,34 @@ | ||
52 | 69 | this.outputStyle = outputStyle; |
53 | 70 | } |
54 | 71 | |
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 | + | |
55 | 100 | public abstract String toString(T target); |
56 | 101 | |
57 | 102 | } |
@@ -79,9 +79,12 @@ | ||
79 | 79 | // 要素管理に登録 |
80 | 80 | folders.put(resource.getFullPath(), node); |
81 | 81 | } 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 | + } | |
85 | 88 | } else { |
86 | 89 | // 取り扱い不明なリソース |
87 | 90 | String msg = String.format( |
@@ -34,7 +34,10 @@ | ||
34 | 34 | |
35 | 35 | private TreeWriter writer; |
36 | 36 | |
37 | - private SpyArg<T> arg; | |
37 | + /** | |
38 | + * パラメータ | |
39 | + */ | |
40 | + protected SpyArg<T> arg; | |
38 | 41 | |
39 | 42 | public AbstractTreeSpyJob(Display display, String name, TreeWriter writer, SpyArg<T> arg) { |
40 | 43 | super(display, name); |