Author: scabanovich
Date: 2011-07-27 20:19:59 -0400 (Wed, 27 Jul 2011)
New Revision: 33284
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/KBSettingsPreferencePage.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties
trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java
Log:
JBIDE-9120
https://issues.jboss.org/browse/JBIDE-9120
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2011-07-28 00:19:44
UTC (rev 33283)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/META-INF/MANIFEST.MF 2011-07-28 00:19:59
UTC (rev 33284)
@@ -25,6 +25,7 @@
org.eclipse.wst.css.core;bundle-version="1.1.500",
org.eclipse.wst.html.core;bundle-version="1.1.500",
org.jboss.tools.common.el.ui,
+ org.jboss.tools.common.ui,
org.eclipse.wst.common.project.facet.core;bundle-version="1.4.200",
org.eclipse.jst.j2ee;bundle-version="1.1.500"
Bundle-ActivationPolicy: lazy
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties 2011-07-28 00:19:44 UTC
(rev 33283)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.properties 2011-07-28 00:19:59 UTC
(rev 33284)
@@ -7,4 +7,5 @@
KBBuilderProblemName=Knowledge Base Builder Problem
BuilderOrderProblemName=Builders Order Problem
-ELValidator=EL Validator
\ No newline at end of file
+ELValidator=EL Validator
+PreferencePage_KBSettings=JBoss Tools Knowledge Base
\ No newline at end of file
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2011-07-28 00:19:44 UTC (rev
33283)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.kb/plugin.xml 2011-07-28 00:19:59 UTC (rev
33284)
@@ -291,4 +291,18 @@
</javaCompletionProposalComputer>
</extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ name="%PreferencePage_KBSettings"
+
class="org.jboss.tools.jst.web.kb.preferences.KBSettingsPreferencePage"
+
id="org.jboss.tools.jst.web.kb.propertyPages.KBSettingsPreferencePage">
+ <enabledWhen>
+ <adapt type="org.eclipse.core.resources.IProject">
+ <test property="org.eclipse.core.resources.projectNature"
value="org.eclipse.jdt.core.javanature"/>
+ </adapt>
+ </enabledWhen>
+ </page>
+ </extension>
+
</plugin>
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java 2011-07-28
00:19:44 UTC (rev 33283)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.java 2011-07-28
00:19:59 UTC (rev 33284)
@@ -37,4 +37,6 @@
public static String ILLEGAL_CONTENTTYPE;
public static String EXCEPTION_DURING_CREATING_MARKER;
+
+ public static String KB_SETTINGS_PREFERENCE_PAGE_KB_SUPPORT;
}
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties 2011-07-28
00:19:44 UTC (rev 33283)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/KbMessages.properties 2011-07-28
00:19:59 UTC (rev 33284)
@@ -14,4 +14,6 @@
ILLEGAL_CONTENTTYPE=Unknown contentType argument value: {0}
-EXCEPTION_DURING_CREATING_MARKER=Exception occurred during creating marker for validation
error on ''{0}''
\ No newline at end of file
+EXCEPTION_DURING_CREATING_MARKER=Exception occurred during creating marker for validation
error on ''{0}''
+
+KB_SETTINGS_PREFERENCE_PAGE_KB_SUPPORT=JBoss Tools Knowledge Base support\:
\ No newline at end of file
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java 2011-07-28
00:19:44 UTC (rev 33283)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/WebKbPlugin.java 2011-07-28
00:19:59 UTC (rev 33284)
@@ -6,12 +6,17 @@
import java.util.Set;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ISaveContext;
import org.eclipse.core.resources.ISaveParticipant;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.jst.web.WebModelPlugin;
+import org.jboss.tools.jst.web.kb.internal.KbBuilder;
import org.jboss.tools.jst.web.kb.internal.KbProject;
import org.osgi.framework.BundleContext;
@@ -134,4 +139,21 @@
public static WebKbPlugin getDefault() {
return plugin;
}
+
+ public static void enableKB(IProject project, IProgressMonitor monitor) {
+ try {
+ WebModelPlugin.addNatureToProjectWithValidationSupport(project, KbBuilder.BUILDER_ID,
IKbProject.NATURE_ID);
+ } catch (CoreException e) {
+ getDefault().logError(e);
+ }
+ }
+
+ public static void disableKB(IProject project) {
+ try {
+ EclipseUtil.removeNatureFromProject(project, IKbProject.NATURE_ID);
+ } catch (CoreException e) {
+ getDefault().logError(e);
+ }
+ }
+
}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/KBSettingsPreferencePage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/KBSettingsPreferencePage.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/KBSettingsPreferencePage.java 2011-07-28
00:19:59 UTC (rev 33284)
@@ -0,0 +1,155 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.kb.preferences;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.jboss.tools.common.ui.preferences.SettingsPage;
+import org.jboss.tools.common.ui.widget.editor.IFieldEditor;
+import org.jboss.tools.common.ui.widget.editor.IFieldEditorFactory;
+import org.jboss.tools.jst.web.kb.KbMessages;
+import org.jboss.tools.jst.web.kb.KbProjectFactory;
+import org.jboss.tools.jst.web.kb.WebKbPlugin;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class KBSettingsPreferencePage extends SettingsPage {
+
+ public static final String ID =
"org.jboss.tools.jst.web.kb.propertyPages.KBSettingsPreferencePage";
//$NON-NLS-1$
+
+ private IProject project;
+ private boolean kbEnabled;
+ private boolean initialState;
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.ui.dialogs.PropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ public void setElement(IAdaptable element) {
+ super.setElement(element);
+ project = (IProject) getElement().getAdapter(IProject.class);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite root = new Composite(parent, SWT.NONE);
+
+ GridData gd = new GridData();
+
+ gd.horizontalSpan = 1;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ gd.grabExcessVerticalSpace = false;
+
+ GridLayout gridLayout = new GridLayout(1, false);
+ root.setLayout(gridLayout);
+
+ Composite generalGroup = new Composite(root, SWT.NONE);
+ generalGroup.setLayoutData(gd);
+ gridLayout = new GridLayout(4, false);
+
+ generalGroup.setLayout(gridLayout);
+
+ initialState = isKBEnabled(project);
+ IFieldEditor kbSupportCheckBox = IFieldEditorFactory.INSTANCE.createCheckboxEditor(
+ KbMessages.KB_SETTINGS_PREFERENCE_PAGE_KB_SUPPORT,
KbMessages.KB_SETTINGS_PREFERENCE_PAGE_KB_SUPPORT, initialState);
+ kbSupportCheckBox.addPropertyChangeListener(new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent evt) {
+ Object value = evt.getNewValue();
+ if (value instanceof Boolean) {
+ boolean v = ((Boolean) value).booleanValue();
+ setEnabledKBSuport(v);
+ }
+ }
+ });
+ kbEnabled = isKBEnabled(project);
+ registerEditor(kbSupportCheckBox, generalGroup);
+
+ validate();
+ return root;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+ */
+ @Override
+ protected void performDefaults() {
+ getEditor(KbMessages.KB_SETTINGS_PREFERENCE_PAGE_KB_SUPPORT).setValue(isKBEnabled(project));
+ validate();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performOk()
+ */
+ @Override
+ public boolean performOk() {
+ if(isKBEnabled()!=initialState) {
+ if(isKBEnabled()) {
+ addKBSupport(project);
+ } else {
+ removeKBSupport(project);
+ }
+ }
+ return true;
+ }
+
+ private void addKBSupport(IProject project) {
+ if(project==null) {
+ return;
+ }
+ WebKbPlugin.enableKB(project, new NullProgressMonitor());
+ }
+
+ private void removeKBSupport(IProject project) {
+ WebKbPlugin.disableKB(project);
+ }
+
+ private boolean isKBEnabled(IProject project) {
+ return KbProjectFactory.getKbProject(project, false) != null;
+ }
+
+ private boolean isKBEnabled() {
+ return kbEnabled;
+ }
+
+ public void setEnabledKBSuport(boolean enabled) {
+ kbEnabled = enabled;
+ editorRegistry.get(KbMessages.KB_SETTINGS_PREFERENCE_PAGE_KB_SUPPORT).setValue(enabled);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.common.ui.preferences.SettingsPage#validate()
+ */
+ @Override
+ protected void validate() {
+ }
+
+ public void dispose() {
+ super.dispose();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.kb/src/org/jboss/tools/jst/web/kb/preferences/KBSettingsPreferencePage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain