incubator-imperius-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jnee...@apache.org
Subject svn commit: r612031 [3/6] - in /incubator/imperius/trunk: ./ imperius-javasplextension/ imperius-javasplextension/META-INF/ imperius-javasplextension/src/ imperius-javasplextension/src/org/ imperius-javasplextension/src/org/apache/ imperius-javasplexte...
Date Tue, 15 Jan 2008 06:53:02 GMT
Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyFileDocumentProvider.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyFileDocumentProvider.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyFileDocumentProvider.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyFileDocumentProvider.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.editor.tool.ui;
+
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.IPolicyPartitionScanner;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.PolicyPartitionScannerImpl;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.FastPartitioner;
+import org.eclipse.ui.editors.text.FileDocumentProvider;
+
+
+public class PolicyFileDocumentProvider extends FileDocumentProvider {
+
+	public PolicyFileDocumentProvider() {
+
+	}
+
+	protected IDocument createDocument(Object anElement) throws CoreException {
+		// System.out.println("anElement-->"+anElement); 
+		// anElement-->org.eclipse.ui.part.FileEditorInput(/as/a.spl)
+		IDocument document = super.createDocument(anElement);
+		if (document != null) {
+			// create partition scanner
+			IPolicyPartitionScanner policyPartitionScanner = new PolicyPartitionScannerImpl();
+			policyPartitionScanner.setGenericPartitionRules();
+
+			IDocumentPartitioner partitioner = new FastPartitioner(
+					(PolicyPartitionScannerImpl) policyPartitionScanner,
+					PolicyPartitionScannerImpl.getDocumentPartitionTypes());
+			partitioner.connect(document);
+			document.setDocumentPartitioner(partitioner);
+		}
+		return document;
+	}
+
+}
\ No newline at end of file

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyFileDocumentProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyReconcilingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyReconcilingStrategy.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyReconcilingStrategy.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyReconcilingStrategy.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.editor.tool.ui;
+
+import java.io.StringReader;
+
+import org.apache.imperius.spl.editor.tool.internal.builder.PolicyFileParser;
+import org.apache.imperius.spl.editor.tool.utils.PolicyCacheUtil;
+import org.apache.imperius.spl.editor.tool.utils.PolicyFileImportStmtParserUtil;
+import org.apache.imperius.spl.editor.tool.utils.PolicyPluginLogUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
+
+
+public class PolicyReconcilingStrategy implements IReconcilingStrategy {
+
+	private PolicyEditor fEditor;
+	private PolicyFileImportStmtParserUtil fPolicyFileImportParser;
+	
+	/**
+	 * 
+	 * @param anEditor
+	 */
+	public PolicyReconcilingStrategy(PolicyEditor anEditor) {
+		fEditor = anEditor;
+		fPolicyFileImportParser = PolicyFileImportStmtParserUtil.getParserInstance(fEditor);
+	}
+
+	/**
+	 * 
+	 */
+	public void setDocument(IDocument document) {
+	}
+
+	/**
+	 * 
+	 */
+	public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+	}
+
+	/**
+	 * 
+	 */
+	public void reconcile(IRegion partition) {
+		parse();
+	}
+
+	/**
+	 * 
+	 */
+	public void parse() {
+		try {
+			IFile resourceFile = fEditor.getActiveEditorFile();
+			PolicyCacheUtil cacheUtil = PolicyCacheUtil.getCacheUtilInstance();
+			cacheUtil.initializeProjectCacheMap(resourceFile.getProject());
+			
+			String parseString = fEditor.getDocument().get();
+			if(parseString.indexOf("Import") != -1) {
+				fPolicyFileImportParser.parsePolicyFileForImportStmts(parseString);
+			}
+				
+			if(parseString.indexOf("Import <stmt>;") == -1) {
+				StringReader reader = new StringReader(parseString);
+				PolicyFileParser.getParserInstance().parseFile(resourceFile.getName(), resourceFile, reader);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			PolicyPluginLogUtil.logMessage(e.getMessage());
+		}
+	}
+
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyReconcilingStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicySourceViewerConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicySourceViewerConfiguration.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicySourceViewerConfiguration.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicySourceViewerConfiguration.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.editor.tool.ui;
+
+import org.apache.imperius.spl.editor.tool.ui.internal.contentassistant.PolicyCompletionProcessor;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.IPolicyPartitionScanner;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.PolicyFileCommentScanner;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.PolicyFileDefaultCodeScanner;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.PolicyPartitionScannerImpl;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.reconciler.IReconciler;
+import org.eclipse.jface.text.reconciler.MonoReconciler;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+public class PolicySourceViewerConfiguration extends SourceViewerConfiguration {
+
+	private PolicyEditor fEditor;
+	
+	public PolicySourceViewerConfiguration(PolicyEditor anEditor) {
+		fEditor = anEditor;
+	}
+	
+	/**
+	 * Returns all configured content types for the given source viewer. This list
+	 * tells the caller which content types must be configured for the given source
+	 * viewer, i.e. for which content types the given source viewer's functionalities
+	 * must be specified. 
+	 *
+	 * @param sourceViewer the source viewer to be configured by this configuration
+	 * @return the configured content types for the given viewer
+	 */
+	public String[] getConfiguredContentTypes(ISourceViewer aSourceViewer) {
+		return PolicyPartitionScannerImpl.getDocumentPartitionTypes();
+	}
+	
+    /**
+	 * Returns the presentation reconciler ready to be used with the given source viewer.
+	 *
+	 * @param sourceViewer the source viewer
+	 * @return the presentation reconciler or <code>null</code> if presentation reconciling should not be supported
+     */
+	public IPresentationReconciler getPresentationReconciler(ISourceViewer aViewer) {
+		
+		PresentationReconciler reconciler = new PresentationReconciler();
+
+		// get Token Color Manager
+		IPolicyTokenColorManager pTokenColorManager = PolicyTokenColorManagerImpl.getTokenColorManagerInstance();
+
+		// set reconciler to generic partitions ie comments
+		DefaultDamagerRepairer damagerRepairer = new DefaultDamagerRepairer(new PolicyFileCommentScanner(pTokenColorManager));
+		reconciler.setDamager(damagerRepairer, IPolicyPartitionScanner.SPL_SINGLELINE_COMMENT);
+		reconciler.setRepairer(damagerRepairer, IPolicyPartitionScanner.SPL_SINGLELINE_COMMENT);
+
+		damagerRepairer = new DefaultDamagerRepairer(new PolicyFileCommentScanner(pTokenColorManager));
+		reconciler.setDamager(damagerRepairer, IPolicyPartitionScanner.SPL_MULTILINE_COMMENT);
+		reconciler.setRepairer(damagerRepairer, IPolicyPartitionScanner.SPL_MULTILINE_COMMENT);
+		
+		damagerRepairer = new DefaultDamagerRepairer(new PolicyFileDefaultCodeScanner(pTokenColorManager));
+		reconciler.setDamager(damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
+		reconciler.setRepairer(damagerRepairer, IDocument.DEFAULT_CONTENT_TYPE);
+
+		return reconciler;
+	}
+	
+	/**
+	 * 
+	 */
+	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+		ContentAssistant assistant = new ContentAssistant();
+		assistant.setContentAssistProcessor(new PolicyCompletionProcessor(fEditor), IDocument.DEFAULT_CONTENT_TYPE);
+		assistant.enableAutoActivation(true);
+		assistant.setAutoActivationDelay(200);
+		assistant.setProposalPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
+		assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_BELOW);
+//		assistant.setContextInformationPopupBackground(PolicyTokenColorManagerImpl.getTokenColorManagerInstance().getColor(IPolicyTokenColorManager.RGB_CONTENT_ASSIST_COLOR));
+//		assistant.setContextInformationPopupBackground(new Color(Display.getCurrent(), new RGB(255, 255, 255)));
+		assistant.setProposalSelectorBackground(new Color(Display.getCurrent(), new RGB(255, 255, 255)));
+		assistant.setProposalSelectorForeground(new Color(Display.getCurrent(), new RGB(0, 0, 0)));
+		return assistant;
+	}
+	
+	/**
+	 * 
+	 */
+	public IReconciler getReconciler(ISourceViewer aSourceViewer) {
+		IReconciler reconciler;
+		if (fEditor != null && (fEditor instanceof PolicyEditor))
+			reconciler = new MonoReconciler(((PolicyEditor) fEditor).getReconcilingStrategy(), false);
+		else
+			reconciler = null;
+		return reconciler;
+	}	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicySourceViewerConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyTokenColorManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyTokenColorManagerImpl.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyTokenColorManagerImpl.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyTokenColorManagerImpl.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+
+package org.apache.imperius.spl.editor.tool.ui;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.imperius.spl.editor.tool.PluginActivator;
+import org.apache.imperius.spl.editor.tool.ui.internal.preferences.IPolicyPreferenceColorConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferenceConverter;
+import org.eclipse.jface.resource.StringConverter;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+
+
+public class PolicyTokenColorManagerImpl implements IPolicyTokenColorManager, IPolicyPreferenceColorConstants {
+
+	private Map colorTable = new HashMap();
+	private Map tokenTable = new HashMap();
+	private static PolicyTokenColorManagerImpl eTokenColorMgrInstance; 
+	  
+	/**
+	 * creates new object
+	 */
+	private PolicyTokenColorManagerImpl() {
+		IPreferenceStore store = PluginActivator.getDefault().getPreferenceStore();
+		initializePreferenceStore(store);
+	}
+	
+	public static PolicyTokenColorManagerImpl getTokenColorManagerInstance() {
+		if(eTokenColorMgrInstance == null) {
+			eTokenColorMgrInstance = new PolicyTokenColorManagerImpl();
+		}
+		return eTokenColorMgrInstance;
+	}
+	
+	private void initializePreferenceStore(IPreferenceStore aStore) {
+		PreferenceConverter.setDefault(aStore, SPL_PREF_DEFAULT_COLOR_ID, RGB_DEFAULT_COLOR);
+		PreferenceConverter.setDefault(aStore, SPL_PREF_COMMENT_COLOR_ID, RGB_COMMENT_COLOR);
+		PreferenceConverter.setDefault(aStore, SPL_PREF_KEYWORD_COLOR_ID, RGB_KEYWORD_COLOR);
+	}
+
+	/**
+	 * return color
+	 */
+	public Color getColor(RGB rgb) {
+		Color color = (Color) colorTable.get(rgb);
+		if (color == null) {
+			color = new Color(Display.getCurrent(), rgb);
+			colorTable.put(rgb, color);
+		}
+		return color;
+	}
+	
+	public IToken getToken(String preferenceColorKey) {
+		IPreferenceStore preferenceStore = PluginActivator.getDefault().getPreferenceStore();
+		Token token = (Token) tokenTable.get(preferenceColorKey);
+		if (token == null) {
+			String colorName = preferenceStore.getString(preferenceColorKey);
+			RGB rgb = StringConverter.asRGB(colorName);
+			token = new Token(new TextAttribute(getColor(rgb), null, 1));
+			tokenTable.put(preferenceColorKey, token);
+		}
+		return token;		
+	}
+	
+	/**
+	 * 
+	 * @param event
+	 * @return
+	 */
+	public boolean affectsTextPresentation(PropertyChangeEvent event) {
+		Token token = (Token) tokenTable.get(event.getProperty());
+		return (token != null);
+	}
+
+	/**
+	 * 
+	 * @param event
+	 */
+	public void handlePreferenceStoreChanged(PropertyChangeEvent event) {
+		IPreferenceStore preferenceStore = PluginActivator.getDefault().getPreferenceStore();
+		String prefKey = event.getProperty();
+		Token token = (Token) tokenTable.get(prefKey);
+		if (token != null) {
+			String colorName = preferenceStore.getString(prefKey);
+			RGB rgb = StringConverter.asRGB(colorName);
+			token.setData(new TextAttribute(getColor(rgb)));
+		}
+	}	
+	
+	public void dispose() {
+		Iterator e = colorTable.values().iterator();
+		while (e.hasNext()) {
+			((Color) e.next()).dispose();
+		}
+	}
+	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/PolicyTokenColorManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/AbstractPolicyFileAction.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/AbstractPolicyFileAction.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/AbstractPolicyFileAction.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/AbstractPolicyFileAction.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+public abstract class AbstractPolicyFileAction implements IObjectActionDelegate {
+
+	protected IFile policyFile;
+	
+	public void setActivePart(IAction iaction, IWorkbenchPart iworkbenchpart) {
+    }
+	
+	public void selectionChanged(IAction action, ISelection selection) {
+		IFile file = null;
+		if(selection instanceof IStructuredSelection) {
+			Object object = ((IStructuredSelection)selection).getFirstElement();
+			if(object != null && object instanceof IFile) {
+				file = (IFile)object;
+			}
+		}
+		policyFile = file;
+	}
+	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/AbstractPolicyFileAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/IPolicyFileActions.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/IPolicyFileActions.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/IPolicyFileActions.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/IPolicyFileActions.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.actions;
+
+/**
+ * @author Administrator
+ *
+ */
+public interface IPolicyFileActions {
+
+	public void exportPolicyFile() throws Exception;
+	
+	public void deployPolicyFile() throws Exception;
+	
+	public void runPolicyFile() throws Exception;
+	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/IPolicyFileActions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/PolicyFileActionImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/PolicyFileActionImpl.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/PolicyFileActionImpl.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/PolicyFileActionImpl.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.actions;
+
+import org.apache.imperius.spl.editor.tool.PluginActivator;
+import org.apache.imperius.spl.editor.tool.internal.builder.PolicyMarkerFactory;
+import org.apache.imperius.spl.editor.tool.internal.client.IPolicyClient;
+import org.apache.imperius.spl.editor.tool.internal.client.IPolicyClientFactory;
+import org.apache.imperius.spl.editor.tool.internal.client.PolicyClientFactoryImpl;
+import org.apache.imperius.spl.editor.tool.internal.messages.PolicyMessages;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+
+
+
+
+public class PolicyFileActionImpl extends AbstractPolicyFileAction {
+
+	private String policyDomain;
+	public void run(IAction anAction) {
+		// check if errors exist
+		IPolicyClientFactory factory = new PolicyClientFactoryImpl();
+		IPolicyClient policyClient = null;
+		try {
+			IMarker[] markers = policyFile.findMarkers(PolicyMarkerFactory.MARKER_ID, false, IResource.DEPTH_INFINITE);
+			String actionId = (String)anAction.getId();
+			policyDomain = PluginActivator.getDefault().getProjectType(policyFile.getProject().getName());
+			if("simulateRun".equals(actionId)) {
+				doPolicyRunSimulation();
+			} else {
+				if(markers.length > 0) {
+					MessageDialog.openError(PluginActivator.getActiveWorkbenchShell(), "Error", PolicyMessages.getString("SPL_FILE_CONTAINS_ERRORS"));
+					return;
+				}
+				policyClient = factory.getClient(policyDomain);
+				if(policyClient != null) { 
+					if("runPolicy".equals(actionId)) {
+						policyClient.doRunPolicy(policyFile);
+					} else if("deployPolicy".equals(actionId)) {
+						policyClient.doDeployPolicy(policyFile);
+					} else if("exportPolicy".equals(actionId)) {
+						policyClient.doDeployPolicy(policyFile);
+					}
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			MessageDialog.openError(PluginActivator.getActiveWorkbenchShell(), PolicyMessages.getString("POLICY_ERROR_TITLE"), e.getMessage());
+		} 
+	}
+	
+	
+	public void doPolicyRunSimulation() {
+		/*PolicySimulationApp simulationAppli = new PolicySimulationApp();
+		simulationAppli.setPolicyString(PolicySimulationUtil.createPolicyString(policyFile));
+		simulationAppli.setPolicyFilePath(PolicySimulationUtil.getAbsolutePath(policyFile));
+		simulationAppli.setPolicyName(policyFile.getName().substring(0, policyFile.getName().indexOf(".")));
+		simulationAppli.setPolicyDomain(policyDomain);
+		simulationAppli.run();*/
+	}
+//	
+//	public static void main(String[] args) {
+//		new PolicyFileActionImpl().doPolicyRunSimulation();
+//	}
+	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/actions/PolicyFileActionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/IPolicyContentAssistantModel.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/IPolicyContentAssistantModel.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/IPolicyContentAssistantModel.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/IPolicyContentAssistantModel.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.contentassistant;
+
+import java.util.List;
+
+/**
+ * @author Administrator
+ *
+ */
+public interface IPolicyContentAssistantModel {
+
+	public List getCompletionsList(String prefix);
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/IPolicyContentAssistantModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyCompletionProcessor.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyCompletionProcessor.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyCompletionProcessor.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyCompletionProcessor.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.contentassistant;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.imperius.spl.editor.tool.ui.PolicyEditor;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+
+public class PolicyCompletionProcessor implements IContentAssistProcessor {
+
+	private PolicyEditor editorObj;
+	
+	
+	public PolicyCompletionProcessor(PolicyEditor anEditor) {
+		editorObj = anEditor;
+	}
+	
+	public ICompletionProposal[] computeCompletionProposals(ITextViewer fViewer, int iDocOffset) {
+		ICompletionProposal[] proposals = null;
+		try {
+			IDocument document = fViewer.getDocument();
+			IRegion range = document.getLineInformationOfOffset(iDocOffset);
+			int start = range.getOffset();
+			String line = document.get(start, iDocOffset - start);
+			String prefix = line.substring(line.lastIndexOf(" ") == -1 ? 0 : line.lastIndexOf(" ")).trim();
+			PolicyContentAssistantModelImpl model = new PolicyContentAssistantModelImpl(editorObj);
+			List cimsplExprs = model.getCompletionsList(prefix);
+			proposals = new CompletionProposal[cimsplExprs.size()];
+			int i = 0;
+			String displayString = "";
+			for (Iterator iter = cimsplExprs.iterator(); iter.hasNext();) {
+				String completion = (String) iter.next();
+				if(completion.indexOf("-") != -1) {
+					displayString = completion;
+					completion = completion.substring(0, completion.indexOf("-")).trim();
+				} else {
+					displayString = completion;
+				}
+				//proposals[i++] = new CompletionProposal(completion, iDocOffset, 0, completion.length());
+				proposals[i++] = new CompletionProposal(completion, iDocOffset, 0, completion.length(),null ,displayString,null,null);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return proposals;
+	}
+
+	public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
+		return null;
+	}
+
+	public char[] getCompletionProposalAutoActivationCharacters() {
+		return (new char[] { '.' });
+	}
+
+	public char[] getContextInformationAutoActivationCharacters() {
+		return null;
+	}
+
+	public String getErrorMessage() {
+		return "No completions available.";
+	}
+
+	public IContextInformationValidator getContextInformationValidator() {
+		return null;
+	}
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyCompletionProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyContentAssistantModelImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyContentAssistantModelImpl.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyContentAssistantModelImpl.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyContentAssistantModelImpl.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.contentassistant;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.imperius.spl.editor.tool.ui.PolicyEditor;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.IPolicyFileCodeSyntax;
+import org.apache.imperius.spl.editor.tool.ui.internal.scanners.PolicyFileCodeSyntaxImpl;
+import org.apache.imperius.spl.editor.tool.utils.AbstractClassDetails;
+import org.apache.imperius.spl.editor.tool.utils.ClassMethod;
+import org.apache.imperius.spl.editor.tool.utils.ClassProperty;
+import org.apache.imperius.spl.editor.tool.utils.MethodParameter;
+import org.apache.imperius.spl.editor.tool.utils.PolicyCacheUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.text.IDocument;
+
+
+public class PolicyContentAssistantModelImpl implements IPolicyContentAssistantModel {
+
+	private PolicyEditor editorObj;
+	
+	private IPolicyFileCodeSyntax policySyntax;
+	
+	private String fClassName = "";
+	
+	public PolicyContentAssistantModelImpl(PolicyEditor anEditor) {
+		editorObj = anEditor;
+		policySyntax = new PolicyFileCodeSyntaxImpl();
+	}
+	
+	private IFile getEditorFile() {
+		return editorObj.getActiveEditorFile();
+	}
+	
+	
+	private IProject getCurrProject() {
+		return getEditorFile().getProject();
+	}
+
+	public List getCompletionsList(String prefix) {
+		List allExprsList = new ArrayList();
+		// if there is no prefix get all expressions
+		if ("".equals(prefix) && !prefix.endsWith(".")) {
+			allExprsList.addAll(policySyntax.getPolicyExpressions());
+			// add custom actions
+			allExprsList.addAll(policySyntax.getCustomExpressions(getCurrProject()));
+			allExprsList.addAll(policySyntax.getCustomActions(getCurrProject()));
+		} else {
+			// check if the prefix is present in the current editor import statement
+			if(isPrefixPresentInDocument(prefix)) {
+				Map projectsCacheMap = PolicyCacheUtil.projectCacheMapObj;
+				// get properties and methods of this Class form CacheUtil class
+				String currProjectName = getCurrProject().getName();
+				if(projectsCacheMap!= null && projectsCacheMap.size()>0) {
+					// from map get the cache collection object of this current project
+					Map classPropCollection =  (Map)projectsCacheMap.get(currProjectName);
+					// from this map see if prefix class is there or not
+					if(classPropCollection != null && classPropCollection.size()>0) {
+						if(classPropCollection.containsKey(fClassName)) {
+							AbstractClassDetails oClassDetails = (AbstractClassDetails)classPropCollection.get(fClassName);
+							allExprsList.addAll(buildContentAssistantList(oClassDetails));
+						}
+					}
+				}
+			}
+		}
+		return allExprsList;
+	}
+
+	/**
+	 * 
+	 * @param oClassDetails
+	 * @return
+	 */
+	private List buildContentAssistantList(AbstractClassDetails oClassDetails) {
+		List exprList = new ArrayList();
+		if(oClassDetails != null) {
+			exprList.addAll(getClassPropertyNames(oClassDetails.getProperties()));
+			exprList.addAll(getClassMethodNames(oClassDetails.getMethods()));
+		}
+		return exprList;
+	}
+
+	/**
+	 * 
+	 * @param properties
+	 * @return
+	 */
+	private List getClassPropertyNames(List properties) {
+		List propList = new ArrayList();
+		if(properties != null && properties.size() > 0) {
+			for(int i=0;i<properties.size();i++) {
+				Object propObj = properties.get(i);
+				if(propObj instanceof ClassProperty) {
+					ClassProperty classProp = (ClassProperty)propObj;
+					propList.add(classProp.getPropertyName());
+				} else if(propObj instanceof String) {
+					propList.add((String)propObj);
+				}
+			}
+		}
+		return propList;
+	}
+	
+	/**
+	 * 
+	 * @param methodsList
+	 * @return
+	 */
+	private List getClassMethodNames(List methodsList) {
+		List mList = new ArrayList();
+		if(methodsList != null && methodsList.size() > 0) {
+			for(int i=0;i<methodsList.size();i++) {
+				String sMethodSyntax = "";
+				Object methodObj = methodsList.get(i);
+				if(methodObj instanceof ClassMethod) {
+					ClassMethod method = (ClassMethod)methodsList.get(i);
+					sMethodSyntax = sMethodSyntax + method.getMethodName() + "(";
+					String sParameters = "";
+					for(int j=0;j<method.getParamCount();j++) {
+						MethodParameter parameter = method.getParameter(j);
+						
+						String paramType = "".equals(parameter.getReferenceClassName())?parameter.getParamType():parameter.getReferenceClassName();
+						
+						String paramStr = paramType+(parameter.isArray()?"[]":"") + " " + parameter.getParamName();
+						
+						sParameters = sParameters + paramStr + ","; 
+					}
+					sParameters = sParameters.lastIndexOf(",")!=-1?sParameters.substring(0, sParameters.length()-1):sParameters;
+					sMethodSyntax = sMethodSyntax + sParameters + ")";
+					mList.add(sMethodSyntax);
+				} else if(methodObj instanceof String) { 
+					mList.add((String)methodObj);
+				}
+			}
+		}
+		return mList;
+	}	
+
+	/**
+	 * 
+	 * @param prefix
+	 * @return
+	 */
+	private boolean isPrefixPresentInDocument(String prefix) {
+		boolean flag = false;
+		String parseString = ((IDocument)editorObj.getDocument()).get();
+		//System.out.println("parseString2"+parseString);
+		// check if any thing is written
+		if(parseString != null && parseString.length()>0) {
+			// split the string to semi colons
+			String[] semiColonStmts = parseString.split(";");
+			if(semiColonStmts != null && semiColonStmts.length > 0) {
+				for(int i=0;i<semiColonStmts.length;i++) {
+					String tokenStr = semiColonStmts[i];
+					if(tokenStr.indexOf("Import") != -1 && tokenStr.indexOf("Class") != -1) {
+						int colonIndex = 0; 
+						String classname = tokenStr.substring(tokenStr.indexOf("Class")+6,((colonIndex = tokenStr.indexOf(":"))==-1?tokenStr.length():colonIndex)); 
+						String instancesStr = tokenStr.substring(((colonIndex = tokenStr.indexOf(":"))==-1?tokenStr.length():colonIndex+1));
+						if(tokenStr.indexOf("Qualifier") == -1) {
+							String s = prefix.substring(0, prefix.length()-1);
+							if(isValidInstance(classname+","+instancesStr, s)) {
+								flag = true;
+							}
+						} else {
+							if(tokenStr.indexOf((classname = prefix.substring(0, prefix.length()-1))) != -1) {
+								flag = true;
+							}
+						}
+						if(flag) {
+							fClassName = classname.trim();
+							break;
+						}
+						
+					}
+				}
+			} 
+		}
+		return flag;
+	}
+	
+	private boolean isValidInstance(String instancesStr, String prefix) {
+//		System.out.println("instancesStr"+instancesStr);
+//		System.out.println("prefix"+prefix);
+		boolean bFlag = false;
+		String[] instArr = instancesStr.split(",");
+		if(instArr != null && instArr.length > 0) {
+			String instName = "";
+			prefix = prefix.toUpperCase();
+			for(int i=0;i<instArr.length;i++) {
+				if(!"".endsWith(instArr[i].trim())) {
+					instName = instArr[i].trim().toUpperCase();
+					int index = -1;
+					if(prefix.length() == instName.length()) {
+						if(prefix.equals(instName)) {
+							bFlag = true;
+							break;
+						}
+					} else if(prefix.length() > instName.length()) {
+						if(prefix.endsWith(instName)) {
+							index = prefix.indexOf(instName);
+							if(Character.isJavaLetterOrDigit(prefix.charAt(index-1))) {
+								continue;
+							} else {
+								bFlag = true;
+								break;
+							}
+						}
+					} 
+				}
+			}
+		}
+		return bFlag;
+	}
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentassistant/PolicyContentAssistantModelImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IOutlineViewObserver.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IOutlineViewObserver.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IOutlineViewObserver.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IOutlineViewObserver.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.contentoutline;
+
+import antlr.collections.AST;
+
+public interface IOutlineViewObserver {
+	
+	public void setAST(AST tree);
+
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IOutlineViewObserver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IPolicyOutlineViewModel.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IPolicyOutlineViewModel.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IPolicyOutlineViewModel.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IPolicyOutlineViewModel.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.contentoutline;
+
+import org.apache.imperius.spl.editor.tool.utils.PolicyContentOutlineTreeUtil;
+
+public interface IPolicyOutlineViewModel {
+
+	public Object[] getRootElements();
+	
+	public boolean hasChildren(Object aParent);
+	
+	public Object[] getChildren(Object aParent);
+
+	public void setOutlineTree(PolicyContentOutlineTreeUtil treeDataMap);
+	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/IPolicyOutlineViewModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewModelImpl.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewModelImpl.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewModelImpl.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewModelImpl.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.contentoutline;
+
+import org.apache.imperius.spl.editor.tool.utils.PolicyContentOutlineTreeUtil;
+import org.apache.imperius.spl.editor.tool.utils.PolicyTokenNode;
+
+
+public class PolicyOutlineViewModelImpl implements IPolicyOutlineViewModel {
+
+	private PolicyContentOutlineTreeUtil policyTree;
+	
+	public PolicyOutlineViewModelImpl() {
+		
+	}
+	
+	public Object[] getRootElements() {
+		policyTree = (policyTree == null ? new PolicyContentOutlineTreeUtil():policyTree);
+		PolicyTokenNode rootNode = policyTree.getRootElement();
+		if(rootNode != null) {
+			return rootNode.getChildren().toArray();
+		}
+		return new Object[]{};
+		
+	}
+	
+	public boolean hasChildren(Object aParent) {
+		if(aParent instanceof PolicyTokenNode) {
+			return ((PolicyTokenNode)aParent).hasChildren();
+		}
+		return false;
+	}
+	
+	public Object[] getChildren(Object aParent) {
+		if(aParent instanceof PolicyTokenNode) {
+			return ((PolicyTokenNode)aParent).getChildren().toArray();
+		}
+		return new Object[]{};
+	}
+	
+	public void setOutlineTree(PolicyContentOutlineTreeUtil treeDataMap) {
+		policyTree = treeDataMap;
+		//policyTree = (treeDataMap == null? new PolicyContentOutlineTreeUtil():treeDataMap);
+	}
+	
+	
+}
+

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewModelImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewPage.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewPage.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewPage.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewPage.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,298 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.contentoutline;
+
+import org.apache.imperius.spl.editor.tool.internal.messages.PolicyMessages;
+import org.apache.imperius.spl.editor.tool.ui.PolicyEditor;
+import org.apache.imperius.spl.editor.tool.utils.PolicyContentOutlineTreeUtil;
+import org.apache.imperius.spl.editor.tool.utils.PolicyTokenNode;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IPositionUpdater;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+
+import antlr.collections.AST;
+
+
+/**
+ * @author Administrator
+ *
+ */
+public class PolicyOutlineViewPage extends ContentOutlinePage implements IOutlineViewObserver {
+
+	private PolicyEditor _editorObj;
+	
+	private IDocumentProvider _documentProvider;
+	
+	private Object _input;
+	
+	private static final String SEGMENTS = "__policy_segments";
+	
+	private IPolicyOutlineViewModel outlineViewModel;
+	
+	private static String policyKeywords = PolicyMessages.getString("POLICY_KEYWORDS");
+	
+	public PolicyOutlineViewPage(PolicyEditor anEditor) {
+		_editorObj = anEditor;
+		_documentProvider = anEditor.getDocumentProvider();
+		outlineViewModel = new PolicyOutlineViewModelImpl();
+	}
+	
+	public void setInput(Object anInput) {
+		_input = anInput;
+	}
+
+	public void createControl(Composite parent) {
+		super.createControl(parent);
+		TreeViewer viewer = super.getTreeViewer();
+		viewer.setContentProvider(new PolicyOutlineContentProvider());
+		viewer.setLabelProvider(new PolicyOutlineLabelProvider());
+		viewer.addSelectionChangedListener(this);
+		viewer.setInput(_input);		
+	}
+	
+	public void updateOutlineView() {
+		TreeViewer viewer = getTreeViewer();
+		if (viewer != null) {
+			Control control = viewer.getControl();
+			if (control != null && !control.isDisposed()) {
+				control.setRedraw(false);
+				viewer.setInput(_input);
+				viewer.expandAll();
+				control.setRedraw(true);
+			}
+		}		
+	}
+	
+	public void setAST(AST tree) {
+		// first traverse the tree and build model
+		traverseAST(tree);
+		Display.getDefault().syncExec(new Runnable() {
+			 public void run() {
+				 updateOutlineView(); 
+			 }
+		});
+	}
+	
+	public void traverseAST(AST astTree) {
+		PolicyContentOutlineTreeUtil t = new PolicyContentOutlineTreeUtil();
+		PolicyTokenNode rootNode = new PolicyTokenNode(_editorObj.getActiveEditorFile().getName(), null);
+		t.setRootElement(rootNode);
+		addToRootNode(rootNode, astTree);
+		outlineViewModel.setOutlineTree(t);
+	}
+	
+	public void addToRootNode(PolicyTokenNode rootNode, AST astTree) {
+		PolicyTokenNode node = null;
+		if(astTree != null) {
+			if(policyKeywords.indexOf(astTree.getText()) != -1) {
+				node = new PolicyTokenNode(astTree.getText(), getPosition(_editorObj, astTree.getLine(), astTree.getText()));
+				node.setLineno(astTree.getLine());
+				rootNode.addChild(node);
+				if("Policy".equals(astTree.getText())) {
+					createPolicyNodeTree(node, astTree.getFirstChild());
+				}
+				if("PolicyGroup".equals(astTree.getText())) {
+					createPolicyGroupNodeTree(node, astTree.getFirstChild());
+				}
+				addToRootNode(rootNode,astTree.getNextSibling());
+			}
+		}
+	}
+	
+	private void createPolicyNodeTree(PolicyTokenNode policyNode, AST tree) {
+		PolicyTokenNode node = null;
+		if(tree != null) {
+			if(policyKeywords.indexOf(tree.getText()) != -1) {
+				node = new PolicyTokenNode(tree.getText(), getPosition(_editorObj, tree.getLine(), tree.getText()));
+				node.setLineno(tree.getLine());
+				policyNode.addChild(node);
+			}
+			createPolicyNodeTree(policyNode, tree.getNextSibling());
+		}
+	}
+	
+	private void createPolicyGroupNodeTree(PolicyTokenNode policyGroupNode, AST tree) {
+		PolicyTokenNode node = null;
+		if(tree != null) {
+			if(policyKeywords.indexOf(tree.getText()) != -1) {
+				node = new PolicyTokenNode(tree.getText(), getPosition(_editorObj, tree.getLine(), tree.getText()));
+				node.setLineno(tree.getLine());
+				policyGroupNode.addChild(node);
+				if("Policy".equals(tree.getText())) {
+					createPolicyNodeTree(node, tree.getFirstChild());
+				}
+			}
+			createPolicyGroupNodeTree(policyGroupNode, tree.getNextSibling());
+		}
+	}
+
+	/**
+	 * 
+	 * @param editor
+	 * @param line
+	 * @return
+	 */
+	public Position getPosition(PolicyEditor editor, int line, String text) {
+		Position pos = null;
+		try {
+			IDocument document = editor.getDocument();
+			if(document != null) {
+				int offset = document.getLineOffset(line);
+				int startOffset = document.search(offset, text, false, true, true);
+				pos = new Position(startOffset);
+				//document.addPosition(SEGMENTS, pos);
+			}
+		} catch (Exception e) {
+			// do nothing
+		}
+//		catch (BadPositionCategoryException e) {
+//			e.printStackTrace();
+//		} catch (BadLocationException e) {
+//			e.printStackTrace();
+//		}
+		return pos;
+	}
+
+	public void selectionChanged(SelectionChangedEvent event) {
+		super.selectionChanged(event);
+		ISelection selection = event.getSelection();
+		if (selection.isEmpty()) {
+			_editorObj.resetHighlightRange();
+		} else {
+			PolicyTokenNode policySegment = (PolicyTokenNode) ((IStructuredSelection) selection).getFirstElement();
+			int start = policySegment.getNodePosition().getOffset();
+			int length = policySegment.getNodeName().length();
+			try {
+				_editorObj.setHighlightRange(start, length, true);
+				_editorObj.selectAndReveal(start,length);
+			} catch (IllegalArgumentException _ex) {
+				_editorObj.resetHighlightRange();
+			}
+		}
+	}		
+	
+	// label provider
+	
+	class PolicyOutlineLabelProvider extends LabelProvider {
+
+		public Image getImage(Object arg0) {
+			return null;
+		}
+
+		public String getText(Object arg0) {
+			if (arg0 instanceof PolicyTokenNode) {
+				return ((PolicyTokenNode) arg0).getNodeName();
+			}
+			return "<Noname>";
+		}
+		
+		public void addListener(ILabelProviderListener arg0) {
+		}
+		
+		public void dispose() {
+		}
+		
+		public boolean isLabelProperty(Object arg0, String arg1) {
+			return false;
+		}
+		
+		public void removeListener(ILabelProviderListener arg0) {
+		}
+	}
+
+	// content provider
+	
+	class PolicyOutlineContentProvider implements ITreeContentProvider {
+		
+		private IPositionUpdater _positionUpdater;
+		
+		public PolicyOutlineContentProvider() {
+			_positionUpdater = new DefaultPositionUpdater(SEGMENTS);
+		}
+		
+  		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+			if(oldInput != null) {
+				IDocument document = _documentProvider.getDocument(oldInput);
+				if(document != null) {
+					if (document != null) {
+						try {
+							document.removePositionCategory(SEGMENTS);
+						} catch(BadPositionCategoryException _ex) {
+						}
+						document.removePositionUpdater(_positionUpdater);
+					}
+				}
+			}
+			
+			if(newInput != null) {
+				IDocument document = _documentProvider.getDocument(newInput);
+				if (document != null) {
+					document.addPositionCategory(SEGMENTS);
+					document.addPositionUpdater(_positionUpdater);
+				}				
+			}
+		}
+		
+		public Object getParent(Object element) {
+			return element;
+		}
+		
+		public void dispose() {
+		}
+		
+		public boolean isDeleted(Object element) {
+			return false;
+		}
+		
+		public Object[] getElements(Object element) {
+			return outlineViewModel.getRootElements();
+		}
+		
+		public boolean hasChildren(Object element) {
+			return outlineViewModel.hasChildren(element);
+		}
+		
+		public Object[] getChildren(Object element) {
+			return outlineViewModel.getChildren(element);
+		}
+	}
+
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/contentoutline/PolicyOutlineViewPage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/IPolicyPreferenceColorConstants.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/IPolicyPreferenceColorConstants.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/IPolicyPreferenceColorConstants.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/IPolicyPreferenceColorConstants.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.preferences;
+
+public interface IPolicyPreferenceColorConstants {
+
+	public static final String SPL_PREF_COMMENT_COLOR_ID = "org.apache.imperius.spl.editor.ui.color.comment";
+	public static final String SPL_PREF_KEYWORD_COLOR_ID = "org.apache.imperius.spl.editor.ui.color.keyword";
+	public static final String SPL_PREF_DEFAULT_COLOR_ID = "org.apache.imperius.spl.editor.ui.color.default";
+	
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/IPolicyPreferenceColorConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyEditorPreferencePage.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyEditorPreferencePage.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyEditorPreferencePage.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyEditorPreferencePage.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.preferences;
+
+import org.apache.imperius.spl.editor.tool.PluginActivator;
+import org.eclipse.jface.preference.ColorFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class PolicyEditorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+	/**
+	 * 
+	 */
+	public PolicyEditorPreferencePage() {
+		super(FieldEditorPreferencePage.GRID);
+		setPreferenceStore(PluginActivator.getDefault().getPreferenceStore());
+		setDescription("Policy editor settings:");
+	}
+
+	/**
+	 * 
+	 */
+	protected void createFieldEditors() {
+		addField(new ColorFieldEditor(IPolicyPreferenceColorConstants.SPL_PREF_COMMENT_COLOR_ID, "&Comments", getFieldEditorParent()));
+		addField(new ColorFieldEditor(IPolicyPreferenceColorConstants.SPL_PREF_KEYWORD_COLOR_ID, "&Keywords", getFieldEditorParent()));
+	}
+
+	public void init(IWorkbench workbench) {
+
+	}
+
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyEditorPreferencePage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyPreferencePage.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyPreferencePage.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyPreferencePage.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyPreferencePage.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author Administrator
+ *
+ */
+public class PolicyPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+	public void init(IWorkbench workbench) {
+	}
+
+	protected Control createContents(Composite aParent) {
+		Composite container = new Composite(aParent, 0);
+		
+		return container;
+	}
+
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyPreferencePage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyServerPreferencePage.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyServerPreferencePage.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyServerPreferencePage.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyServerPreferencePage.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+ 
+package org.apache.imperius.spl.editor.tool.ui.internal.preferences;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class PolicyServerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+	public void init(IWorkbench workbench) {
+	}
+
+	protected Control createContents(Composite aParent) {
+		Composite container = new Composite(aParent, 0);
+		
+		return container;
+	}
+
+}

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/preferences/PolicyServerPreferencePage.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/properties/AddPolicyCustomJarPropertyPage.java
URL: http://svn.apache.org/viewvc/incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/properties/AddPolicyCustomJarPropertyPage.java?rev=612031&view=auto
==============================================================================
--- incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/properties/AddPolicyCustomJarPropertyPage.java (added)
+++ incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/properties/AddPolicyCustomJarPropertyPage.java Mon Jan 14 22:52:53 2008
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.  
+ */
+
+/**
+ * @author Naidu Javvadi <njavvadi@in.ibm.com>
+ *
+ */
+
+package org.apache.imperius.spl.editor.tool.ui.internal.properties;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.imperius.spl.editor.tool.PluginActivator;
+import org.apache.imperius.spl.editor.tool.internal.messages.PolicyMessages;
+import org.apache.imperius.spl.editor.tool.utils.PolicyPluginLogUtil;
+import org.apache.imperius.spl.editor.tool.utils.SPLPolicyUtil;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+
+
+public class AddPolicyCustomJarPropertyPage extends PropertyPage {
+
+	private Text fJarFileText;
+
+	private TableViewer viewer;
+
+	private IProject fProject;
+
+	private String jarFileName = null;
+
+	protected Control createContents(Composite aParent) {
+		setSelectedProject();
+		Composite container = addGridLayout(new Composite(aParent, 0), 1);
+		{
+			Composite container1 = addGridLayout(new Composite(container, 0), 3);
+			Label jarFileLabel = new Label(container1, SWT.NONE);
+			GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+			gridData.horizontalSpan = 1;
+			gridData.widthHint = 100;
+			jarFileLabel.setLayoutData(gridData);
+			jarFileLabel.setText(PolicyMessages
+					.getString("SPL_IMPORT_CUSTOM_JAR_SELECTION_LABEL"));
+
+			fJarFileText = new Text(container1, SWT.BORDER | SWT.SINGLE);
+			gridData = new GridData(GridData.FILL_HORIZONTAL);
+			gridData.horizontalSpan = 1;
+			gridData.widthHint = 280;
+			fJarFileText.setLayoutData(gridData);
+
+			Button fBrowseButton = new Button(container1, SWT.PUSH | SWT.CENTER);
+			fBrowseButton.setText(PolicyMessages.getString("SPL_BROWSE"));
+			gridData = new GridData(GridData.FILL_HORIZONTAL);
+			gridData.horizontalSpan = 1;
+			fBrowseButton.setLayoutData(gridData);
+			fBrowseButton.addSelectionListener(new SelectionAdapter() {
+				public void widgetSelected(SelectionEvent event) {
+					FileDialog fileSelectionDialog = new FileDialog(
+							PluginActivator.getActiveWorkbenchShell(), SWT.NULL);
+					fileSelectionDialog
+							.setFilterExtensions(new String[] { "*.jar" });
+					String filePath = fileSelectionDialog.open();
+					fJarFileText.setText(filePath == null ? "" : filePath);
+					if (filePath != null) {
+						viewer.setInput(getJarEntries(filePath));
+						viewer.refresh();
+					}
+				}
+			});
+
+		}
+
+		// add table to show files in the directory
+		viewer = createTableViewer(container, 1);
+		viewer.setContentProvider(new ContentProvider());
+		viewer.setLabelProvider(new LabelProvider());
+		return container;
+	}
+
+	/**
+	 * 
+	 * @param composite
+	 * @param noOfCols
+	 * @return
+	 */
+	private Composite addGridLayout(Composite composite, int noOfCols) {
+		GridLayout layout = new GridLayout();
+		layout.numColumns = noOfCols;
+		composite.setLayout(layout);
+		return composite;
+	}
+
+	private TableViewer createTableViewer(Composite parent, int span) {
+		Label label = new Label(parent, SWT.NONE);
+		label.setText(PolicyMessages
+				.getString("SPL_ENTRIES_LIST_OF_CUSTOM_JAR"));
+		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.horizontalSpan = 1;
+		gridData.widthHint = 90;
+		label.setLayoutData(gridData);
+		Table table = new Table(parent, SWT.BORDER | SWT.MULTI
+				| SWT.FULL_SELECTION);
+		gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.horizontalSpan = span;
+		gridData.widthHint = 10;
+		gridData.heightHint = 150;
+		table.setLayoutData(gridData);
+
+		TableLayout layout = new TableLayout();
+		layout.addColumnData(new ColumnWeightData(90, true));
+		table.setLayout(layout);
+		TableColumn col = new TableColumn(table, SWT.NONE);
+		col.setText("File Name");
+		col.setResizable(true);
+		return new TableViewer(table);
+	}
+
+	private List getJarEntries(String filePath) {
+		List jarClassEntriesList = new ArrayList();
+		try {
+			JarFile jarFile = new JarFile(filePath);
+			if (jarFile != null) {
+				Enumeration enumerator = jarFile.entries();
+				while (enumerator.hasMoreElements()) {
+					String name = enumerator.nextElement().toString();
+					if (name.indexOf("class") != -1) {
+						if (name.indexOf("$") == -1) {
+							jarClassEntriesList.add(name);
+						}
+					}
+				}
+			}
+		} catch (Exception ex) {
+			System.out.println(ex.getMessage());
+		}
+		return jarClassEntriesList;
+	}
+
+	private void setSelectedProject() {
+		IAdaptable adaptable = (IAdaptable) getElement();
+		fProject = (IProject) adaptable.getAdapter(IProject.class);
+	}
+
+	public boolean performFinish() {
+		if (fProject == null) {
+			MessageDialog.openInformation(getShell(), PolicyMessages
+					.getString("SPL_ERROR_LABEL_NAME"), PolicyMessages
+					.getString("SPL_SELECT_PROJECT"));
+			return false;
+		}
+
+		final String srcPath = fJarFileText.getText();
+		final String destPath = fProject.getLocation().toOSString();
+
+		if ("".equals(srcPath)) {
+			MessageDialog.openInformation(getShell(), PolicyMessages
+					.getString("SPL_ERROR_LABEL_NAME"), PolicyMessages
+					.getString("SPL_SELECT_CUSTOM_ACTIONS_JAR"));
+			return false;
+		}
+
+		if (viewer.getTable().getItemCount() == 0) {
+			MessageDialog.openInformation(getShell(), PolicyMessages
+					.getString("SPL_ERROR_LABEL_NAME"), PolicyMessages
+					.getString("SPL_NO_CLASSES_IN_CUSTOM_ACTIONS_JAR"));
+			return false;
+		}
+
+		try {
+			jarFileName = new File(srcPath).getName();
+			if (jarFileName != null) {
+				boolean isPropFilePresent = extractPropsFileFromJar(srcPath);
+				if (isPropFilePresent) {
+					doImportJarFile(srcPath, destPath, null);
+
+					// add the jar to the class path
+					addJarToClassPath(destPath, jarFileName);
+
+					ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
+							IResource.DEPTH_INFINITE, null);
+					
+					SPLPolicyUtil.loadCustomClasses(fProject);					
+				} else {
+					MessageDialog
+							.openInformation(
+									getShell(),
+									PolicyMessages
+											.getString("SPL_ERROR_LABEL_NAME"),
+									PolicyMessages
+											.getString("SPL_NO_PROPERTIES_FILE_IN_CUSTOM_ACTIONS_JAR"));
+					return false;
+				}
+			}
+		} catch (Exception e) {
+			PolicyPluginLogUtil.logError(PolicyMessages
+					.getString("SPL_JAR_FILE_IMPORT_ERROR_")
+					+ " ", e);
+			return false;
+		}
+		return true;
+	}
+
+	private void doImportJarFile(String srcPath, String destPath,
+			IProgressMonitor monitor) {
+		try {
+			File srcFile = new File(srcPath);
+			File destFile = new File(destPath + File.separator
+					+ srcFile.getName());
+			InputStream in = new FileInputStream(srcFile);
+			OutputStream out = new FileOutputStream(destFile);
+			byte[] buf = new byte[1024];
+			int len;
+			while ((len = in.read(buf)) > 0) {
+				out.write(buf, 0, len);
+			}
+			in.close();
+			out.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	private boolean extractPropsFileFromJar(String srcPath) {
+		boolean flag = false;
+		try {
+			Properties customProps = new Properties();
+			File jarFileObj = new File(srcPath);
+			JarFile jarFile = new JarFile(jarFileObj);
+			if (jarFile != null) {
+				Enumeration enumerator = jarFile.entries();
+				JarEntry entry = null;
+				String entryName = "";
+				String propsFileName = PolicyMessages.SPL_CUSTOM_EXPR_FILE_NAME
+						+ ".properties";
+				while (enumerator.hasMoreElements()) {
+					entry = (JarEntry) enumerator.nextElement();
+					entryName = entry.getName();
+					if (entryName.equals(propsFileName)) {
+						flag = true;
+						InputStream in = jarFile.getInputStream(entry);
+						customProps.load(in);
+						break;
+					}
+				}
+			}
+
+			if (customProps.size() > 0
+					&& customProps.containsKey(PolicyMessages.SPL_CUSTOM_ACTIONS)) {
+				SPLPolicyUtil.loadCustomActions(fProject, customProps,
+						jarFileObj.getName());
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return flag;
+	}
+
+	/**
+	 * this function adds the imported jar file to the classpath
+	 */
+	private void addJarToClassPath(String destPath, String customActJarFileName) {
+		try {
+			// add jar to class path
+			SPLPolicyUtil.addJarToProjectsClasspath(fProject, destPath,
+					customActJarFileName);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void performApply() {
+		if(performFinish()) {
+			super.performApply();
+		}		
+	}
+}
+
+class ContentProvider implements IStructuredContentProvider {
+
+	public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+
+	}
+
+	public Object[] getElements(Object input) {
+		if (input instanceof List) {
+			return ((List) input).toArray();
+		}
+		return new Object[0];
+	}
+
+	public void dispose() {
+	}
+}
+
+class LabelProvider implements ILabelProvider {
+
+	public Image getImage(Object arg0) {
+		return null;
+	}
+
+	public String getText(Object arg0) {
+		if (arg0 instanceof String) {
+			return (String) arg0;
+		}
+		return "";
+	}
+
+	public void addListener(ILabelProviderListener arg0) {
+	}
+
+	public void dispose() {
+	}
+
+	public boolean isLabelProperty(Object arg0, String arg1) {
+		return false;
+	}
+
+	public void removeListener(ILabelProviderListener arg0) {
+	}
+}
\ No newline at end of file

Propchange: incubator/imperius/trunk/imperius-spleditorcore/src/org/apache/imperius/spl/editor/tool/ui/internal/properties/AddPolicyCustomJarPropertyPage.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message