forked from pulse00/Symfony-2-Eclipse-Plugin
/
SymfonyUiPlugin.java
132 lines (108 loc) · 3.81 KB
/
SymfonyUiPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*******************************************************************************
* This file is part of the Symfony eclipse plugin.
*
* (c) Robert Gruendler <r.gruendler@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
******************************************************************************/
package com.dubture.symfony.ui;
import java.io.IOException;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.php.internal.debug.core.PHPDebugPlugin;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.pdtextensions.core.ui.preferences.PHPExecutableChangeListener;
import org.eclipse.php.composer.ui.ComposerUIPlugin;
import com.dubture.symfony.core.SymfonyCorePlugin;
import com.dubture.symfony.core.log.Logger;
import com.dubture.symfony.core.preferences.CorePreferenceConstants.Keys;
import com.dubture.symfony.ui.editor.template.CodeTemplateContextType;
import com.dubture.symfony.ui.preferences.SymfonyTemplateStore;
import com.dubture.symfony.ui.viewsupport.ImagesOnFileSystemRegistry;
/**
* The activator class controls the plug-in life cycle
*/
@SuppressWarnings("restriction")
public class SymfonyUiPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "com.dubture.symfony.ui"; //$NON-NLS-1$
// The shared instance
private static SymfonyUiPlugin plugin;
private ImagesOnFileSystemRegistry fImagesOnFSRegistry;
private SymfonyTemplateStore fCodeTemplateStore;
protected ContextTypeRegistry codeTypeRegistry = null;
/**
* The constructor
*/
public SymfonyUiPlugin() {
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
@SuppressWarnings("deprecation")
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// TODO: implement OpenDocumentListener for file links in
// symfony exception pages
// currently this is not used, as eclipse itself handles this
// event and opens the file
// Display.getDefault().addListener(SWT.OpenDocument, new
// OpenDocumentListener());
try {
PHPDebugPlugin
.getDefault()
.getPluginPreferences()
.addPropertyChangeListener(new PHPExecutableChangeListener(SymfonyCorePlugin.ID, Keys.PHP_EXECUTABLE));
// make sure composer loads the preference listener for the php executable
ComposerUIPlugin.getDefault();
} catch (Exception e) {
Logger.logException(e);
}
}
public void stop(BundleContext context) throws Exception {
super.stop(context);
plugin = null;
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static SymfonyUiPlugin getDefault() {
return plugin;
}
public ImagesOnFileSystemRegistry getImagesOnFSRegistry() {
if (fImagesOnFSRegistry == null) {
fImagesOnFSRegistry = new ImagesOnFileSystemRegistry();
}
return fImagesOnFSRegistry;
}
public TemplateStore getCodeTemplateStore() {
if (fCodeTemplateStore == null) {
fCodeTemplateStore = new SymfonyTemplateStore(getCodeTemplateContextRegistry(), getPreferenceStore(),
PreferenceConstants.CODE_TEMPLATES_KEY);
try {
fCodeTemplateStore.load();
} catch (IOException e) {
Logger.logException(e);
}
}
return fCodeTemplateStore;
}
public ContextTypeRegistry getCodeTemplateContextRegistry() {
if (codeTypeRegistry == null) {
ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
CodeTemplateContextType.registerContextTypes(registry);
codeTypeRegistry = registry;
}
return codeTypeRegistry;
}
}