Révision 2223
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/MediaPreferences.java (revision 2223) | ||
---|---|---|
1 |
package org.txm.backtomedia.commands.function; |
|
2 |
|
|
3 |
import org.eclipse.core.commands.AbstractHandler; |
|
4 |
import org.eclipse.core.commands.ExecutionEvent; |
|
5 |
import org.eclipse.core.commands.ExecutionException; |
|
6 |
import org.eclipse.jface.viewers.ISelection; |
|
7 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
8 |
import org.eclipse.swt.widgets.Display; |
|
9 |
import org.eclipse.swt.widgets.Shell; |
|
10 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
11 |
import org.osgi.service.prefs.BackingStoreException; |
|
12 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
13 |
import org.txm.objects.CorpusCommandPreferences; |
|
14 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
15 |
|
|
16 |
public class MediaPreferences extends AbstractHandler { |
|
17 |
|
|
18 |
@Override |
|
19 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
20 |
|
|
21 |
ISelection isel = HandlerUtil.getCurrentSelection(event); |
|
22 |
if (isel instanceof StructuredSelection) { |
|
23 |
StructuredSelection sel = (StructuredSelection)isel; |
|
24 |
Object o = sel.getFirstElement(); |
|
25 |
if (o instanceof MainCorpus) { |
|
26 |
openPreferences((MainCorpus)o); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
|
|
31 |
return null; |
|
32 |
} |
|
33 |
|
|
34 |
public static boolean openPreferences(MainCorpus corpus) { |
|
35 |
Display d = Display.getCurrent(); |
|
36 |
if (d == null) { |
|
37 |
return false; |
|
38 |
} |
|
39 |
Shell s = d.getActiveShell(); |
|
40 |
MediaPreferencesDialog dialog = new MediaPreferencesDialog(s, corpus); |
|
41 |
if (dialog.open() == MediaPreferencesDialog.OK) { |
|
42 |
CorpusCommandPreferences commandPreferences = corpus.getProject().getCommandPreferences("backtomedia"); |
|
43 |
for (String p : MediaPreferencesDialog.properties) { |
|
44 |
commandPreferences.set(p, dialog.getProperty(p)); |
|
45 |
} |
|
46 |
try { |
|
47 |
commandPreferences.getNode().flush(); |
|
48 |
} catch (BackingStoreException e) { |
|
49 |
e.printStackTrace(); |
|
50 |
return false; |
|
51 |
} |
|
52 |
|
|
53 |
System.out.println("Media preferences updated with "+dialog.getProperties()); |
|
54 |
return true; |
|
55 |
} else { |
|
56 |
System.out.println("Canceled."); |
|
57 |
return false; |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
0 | 61 |
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/MediaPreferencesDialog.java (revision 2223) | ||
---|---|---|
1 |
package org.txm.backtomedia.commands.function; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
|
|
5 |
import org.eclipse.jface.dialogs.Dialog; |
|
6 |
import org.eclipse.swt.SWT; |
|
7 |
import org.eclipse.swt.graphics.Point; |
|
8 |
import org.eclipse.swt.layout.GridData; |
|
9 |
import org.eclipse.swt.layout.GridLayout; |
|
10 |
import org.eclipse.swt.widgets.Composite; |
|
11 |
import org.eclipse.swt.widgets.Control; |
|
12 |
import org.eclipse.swt.widgets.Label; |
|
13 |
import org.eclipse.swt.widgets.Shell; |
|
14 |
import org.eclipse.swt.widgets.Text; |
|
15 |
import org.txm.backtomedia.preferences.BackToMediaPreferences; |
|
16 |
import org.txm.core.preferences.TXMPreferences; |
|
17 |
import org.txm.objects.CorpusCommandPreferences; |
|
18 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
19 |
|
|
20 |
public class MediaPreferencesDialog extends Dialog { |
|
21 |
|
|
22 |
public static String[] properties = {BackToMediaPreferences.STRUCTURE_START_PROPERTY, |
|
23 |
BackToMediaPreferences.STRUCTURE_END_PROPERTY, |
|
24 |
BackToMediaPreferences.STRUCTURE, |
|
25 |
BackToMediaPreferences.WORD_PROPERTY, |
|
26 |
BackToMediaPreferences.SYNCMODE, |
|
27 |
BackToMediaPreferences.MEDIA_DIRECTORY, |
|
28 |
BackToMediaPreferences.MEDIA_FORMAT }; |
|
29 |
|
|
30 |
HashMap<String, Text> fields = new HashMap<String, Text>(); |
|
31 |
HashMap<String, String> values = new HashMap<String, String>(); |
|
32 |
MainCorpus corpus; |
|
33 |
|
|
34 |
protected MediaPreferencesDialog(Shell parentShell, MainCorpus corpus) { |
|
35 |
super(parentShell); |
|
36 |
this.corpus = corpus; |
|
37 |
} |
|
38 |
|
|
39 |
public HashMap<String, String> getProperties() { |
|
40 |
return values; |
|
41 |
} |
|
42 |
|
|
43 |
public String getProperty(String p) { |
|
44 |
return values.get(p); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected Control createDialogArea(Composite parent) { |
|
49 |
Composite container = (Composite) super.createDialogArea(parent); |
|
50 |
Composite c = new Composite(container, SWT.NONE); |
|
51 |
c.setLayout(new GridLayout(2, true)); |
|
52 |
|
|
53 |
CorpusCommandPreferences commandPreferences = corpus.getProject().getCommandPreferences("backtomedia"); |
|
54 |
TXMPreferences alternative = BackToMediaPreferences.getInstance(); |
|
55 |
|
|
56 |
for (String p : properties) { |
|
57 |
new Label(c, SWT.NONE).setText(p); |
|
58 |
Text t = new Text(c, SWT.BORDER); |
|
59 |
t.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
60 |
t.setText(commandPreferences.get(p, alternative)); |
|
61 |
fields.put(p, t); |
|
62 |
} |
|
63 |
return container; |
|
64 |
} |
|
65 |
|
|
66 |
// overriding this methods allows you to set the |
|
67 |
// title of the custom dialog |
|
68 |
@Override |
|
69 |
protected void configureShell(Shell newShell) { |
|
70 |
super.configureShell(newShell); |
|
71 |
newShell.setText("Media preferences"); |
|
72 |
} |
|
73 |
|
|
74 |
// @Override |
|
75 |
// protected Point getInitialSize() { |
|
76 |
// return new Point(450, 300); |
|
77 |
// } |
|
78 |
|
|
79 |
@Override |
|
80 |
protected void okPressed() { |
|
81 |
for (String p : properties) { |
|
82 |
values.put(p, fields.get(p).getText()); |
|
83 |
} |
|
84 |
super.okPressed(); |
|
85 |
} |
|
86 |
} |
|
0 | 87 |
tmp/org.txm.backtomedia.rcp/plugin.xml (revision 2223) | ||
---|---|---|
39 | 39 |
</parameter> |
40 | 40 |
</command> |
41 | 41 |
</menuContribution> |
42 |
<menuContribution |
|
43 |
locationURI="menu:menu.edit?after=org.txm.rcp.separator1"> |
|
44 |
<command |
|
45 |
commandId="org.txm.backtomedia.commands.function.MediaPreferences" |
|
46 |
style="push"> |
|
47 |
</command> |
|
48 |
</menuContribution> |
|
42 | 49 |
</extension> |
43 | 50 |
<extension |
44 | 51 |
point="org.eclipse.ui.commands"> |
... | ... | |
53 | 60 |
id="org.txm.backtomedia.commands.function.BackToMedia" |
54 | 61 |
name="%command.name.0"> |
55 | 62 |
</command> |
63 |
<command |
|
64 |
defaultHandler="org.txm.backtomedia.commands.function.MediaPreferences" |
|
65 |
id="org.txm.backtomedia.commands.function.MediaPreferences" |
|
66 |
name="Open media preferences"> |
|
67 |
</command> |
|
56 | 68 |
</extension> |
57 | 69 |
<extension |
58 | 70 |
point="org.eclipse.ui.editors"> |
Formats disponibles : Unified diff