Permalink
Browse files

SAVARA-312 Initial work to trigger validation of protocols. Defined s…

…avara preferences and a validation property specifically to guard against unnecessary validation
  • Loading branch information...
1 parent 0d3f41c commit 391af002f7844916246fe5d42cf56610c1c56f2d objectiser committed Apr 9, 2012
@@ -36,4 +36,23 @@
</objectContribution>
</extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ objectClass="org.eclipse.core.resources.IFile"
+ class="org.savara.tools.common.properties.SavaraPropertyPage"
+ name="Savara"
+ id="org.savara.tools.common.properties.SavaraPropertyPage"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ objectClass="org.eclipse.core.resources.IFile"
+ class="org.savara.tools.common.properties.ValidationPropertyPage"
+ name="Validation"
+ category="org.savara.tools.common.properties.SavaraPropertyPage"
+ id="org.savara.tools.common.properties.ValidationPropertyPage"/>
+ </extension>
+
</plugin>
@@ -20,11 +20,18 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.savara.tools.common.properties.PropertyDefinitions;
/**
* The activator class controls the plug-in life cycle
@@ -37,7 +44,7 @@
// The shared instance
private static Activator plugin;
- private static Logger logger = Logger.getLogger(Activator.class.getName());
+ private static final Logger LOG=Logger.getLogger(Activator.class.getName());
/**
* The constructor
@@ -69,13 +76,82 @@ public void start(BundleContext context) throws Exception {
bundle.getSymbolicName().startsWith("org.savara.tools.") == false)) {
//if (bundle.getState() == Bundle.RESOLVED) {
- logger.fine("Pre-empt bundle start: "+bundle);
+ LOG.fine("Pre-empt bundle start: "+bundle);
bundle.start();
//}
}
}
}
+ // Register resource change listener
+ IResourceChangeListener rcl=
+ new IResourceChangeListener() {
+
+ public void resourceChanged(IResourceChangeEvent evt) {
+
+ try {
+ evt.getDelta().accept(new IResourceDeltaVisitor() {
+
+ public boolean visit(IResourceDelta delta) {
+ boolean ret=true;
+ IResource res = delta.getResource();
+
+ // Determine if the change is relevant
+ if (isChangeRelevant(res,
+ delta)) {
+
+ // Validate the resource
+ validateResource(res);
+ }
+
+ return(ret);
+ }
+ });
+ } catch(Exception e) {
+ LOG.log(Level.SEVERE, "Failed to process resource change event", e);
+ }
+ }
+ };
+
+ // Register the resource change listener
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(rcl,
+ IResourceChangeEvent.POST_CHANGE);
+
+ }
+
+ /**
+ * This method validates the supplied resource.
+ *
+ * @param res The resource
+ */
+ protected void validateResource(IResource res) {
+
+ try {
+ // TODO: Check if protocol parser available, and if so, then
+ // validate
+ } catch (Exception e) {
+ Activator.logError("Failed to record validation issue on resource '"+res+"'", e);
+ }
+ }
+
+ /**
+ * This method determines whether the supplied resource
+ * change event is relevant.
+ *
+ * @param res The resource
+ * @param deltaFlags The flags
+ * @return Whether the change is relevant
+ */
+ protected boolean isChangeRelevant(IResource res, IResourceDelta delta) {
+ boolean ret=false;
+
+ if (res != null && PropertyDefinitions.isValidationEnabled(res) &&
+ (((delta.getFlags() & IResourceDelta.CONTENT) != 0) ||
+ delta.getKind() == IResourceDelta.ADDED)) {
+ ret = true;
+ }
+
+ return(ret);
}
/*
@@ -111,7 +187,7 @@ public static void logError(String mesg, Throwable t) {
getDefault().getLog().log(status);
}
- logger.log(Level.SEVERE, "LOG ERROR: "+mesg+
+ LOG.log(Level.SEVERE, "LOG ERROR: "+mesg+
(t == null ? "" : ": "+t), t);
}
}
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008-12, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.savara.tools.common.properties;
+
+import org.eclipse.core.resources.IResource;
+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.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+/**
+ * This class provides the base property page for the Savara tools.
+ *
+ */
+public class BasePropertyPage extends PropertyPage {
+
+ private static final String PATH_TITLE = "Path:";
+ protected static final int DEFAULT_INDEX=0;
+
+ /**
+ * Default constructor.
+ */
+ public BasePropertyPage() {
+ super();
+ }
+
+ /**
+ * This method provides information about the resource.
+ *
+ * @param parent
+ */
+ private void addHeaderSection(Composite parent) {
+ Composite composite = createDefaultComposite(parent);
+
+ //Label for path field
+ Label pathLabel = new Label(composite, SWT.NONE);
+ pathLabel.setText(PATH_TITLE);
+
+ // Path text field
+ Text pathValueText = new Text(composite, SWT.WRAP | SWT.READ_ONLY);
+ pathValueText.setEnabled(false);
+ pathValueText.setText(((IResource) getElement()).getFullPath().toString());
+ }
+
+ /**
+ * This method adds the separator.
+ *
+ * @param parent
+ */
+ private void addSeparator(Composite parent) {
+ Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ separator.setLayoutData(gridData);
+ }
+
+ /**
+ * @see PreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL);
+ data.grabExcessHorizontalSpace = true;
+ composite.setLayoutData(data);
+
+ addHeaderSection(composite);
+ addSeparator(composite);
+
+ return composite;
+ }
+
+ /**
+ * This method creates the default composite.
+ *
+ * @param parent The parent composite
+ * @return The new default composite
+ */
+ private Composite createDefaultComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+
+ GridData data = new GridData();
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalAlignment = GridData.FILL;
+ composite.setLayoutData(data);
+
+ return composite;
+ }
+
+ /**
+ * This method resets the properties to their default values.
+ */
+ protected void performDefaults() {
+ }
+
+ /**
+ * This method applies the properties to the persistent
+ * storage associated with the resource.
+ */
+ public boolean performOk() {
+ return true;
+ }
+}
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008-12, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.savara.tools.common.properties;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.savara.tools.common.osgi.Activator;
+
+/**
+ * This interface defines the common property definitions.
+ *
+ */
+public class PropertyDefinitions {
+
+ private static final Logger LOG=Logger.getLogger(PropertyDefinitions.class.getName());
+
+ /**
+ * This property is a boolean flag to indicate whether
+ * validation should be performed on the associated
+ * resource.
+ */
+ public static final String VALIDATE_PROPERTY="savara.validate";
+
+ /**
+ * This method determines whether validation has been enabled for the supplied
+ * resource.
+ *
+ * @param res The resource
+ * @return Whether validation has been enabled
+ */
+ public static boolean isValidationEnabled(IResource res) {
+ boolean ret=false;
+
+ try {
+ String val=res.getPersistentProperty(new QualifiedName(Activator.PLUGIN_ID,
+ PropertyDefinitions.VALIDATE_PROPERTY));
+
+ if (val != null) {
+ ret = Boolean.parseBoolean(val);
+ }
+ } catch (CoreException e) {
+ LOG.log(Level.SEVERE, "Failed to get validation property", e);
+ }
+
+ return(ret);
+ }
+}
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008-12, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.savara.tools.common.properties;
+
+/**
+ * This class provides the property page for the Savara tools.
+ *
+ */
+public class SavaraPropertyPage extends BasePropertyPage {
+
+ /**
+ * Default constructor.
+ */
+ public SavaraPropertyPage() {
+ super();
+ }
+
+}
Oops, something went wrong.

0 comments on commit 391af00

Please sign in to comment.