You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/04/29 16:51:06 UTC
svn commit: r1477113 [14/18] - in
/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide:
./ core/ core/builder/ core/codeassist/ core/extensions/ core/packages/
core/parser/ core/search/ debug/ debug/ui/ debug/ui/handlers/ debug/u...
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaGlobalPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaGlobalPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaGlobalPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaGlobalPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage;
+import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock;
+import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore;
+
+public class RutaGlobalPreferencePage extends AbstractConfigurationBlockPreferencePage {
+
+ @Override
+ protected IPreferenceConfigurationBlock createConfigurationBlock(
+ OverlayPreferenceStore overlayPreferenceStore) {
+ return new RutaGlobalConfigurationBlock(overlayPreferenceStore, this);
+ }
+
+ @Override
+ protected String getHelpId() {
+ return null;
+ }
+
+ @Override
+ protected void setDescription() {
+ String description = RutaPreferencesMessages.RutaGlobalPreferencePage_description;
+ setDescription(description);
+ }
+
+ @Override
+ protected void setPreferenceStore() {
+ setPreferenceStore(RutaIdePlugin.getDefault().getPreferenceStore());
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPreferencesMessages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPreferencesMessages.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPreferencesMessages.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPreferencesMessages.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import org.eclipse.osgi.util.NLS;
+
+public class RutaPreferencesMessages extends NLS {
+ private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.ui.preferences.RutaPreferencesMessages";//$NON-NLS-1$
+
+ private RutaPreferencesMessages() {
+ // Do not instantiate
+ }
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, RutaPreferencesMessages.class);
+ }
+
+ public static String RutaGlobalPreferencePage_description;
+
+ public static String RutaEditorPreferencePage_general;
+
+ public static String RutaSmartTypingConfigurationBlock_typing_smartTab;
+
+ public static String RutaSmartTypingConfigurationBlock_closeBrackets;
+
+ public static String RutaSmartTypingConfigurationBlock_closeStrings;
+
+ public static String RutaSmartTypingConfigurationBlock_closeBraces;
+
+ public static String RutaSmartTypingConfigurationBlock_typing_tabTitle;
+
+ public static String RutaEditorPreferencePage_condition_colors;
+
+ public static String RutaEditorPreferencePage_action_colors;
+
+ public static String RutaEditorPreferencePage_declaration_colors;
+
+ public static String RutaEditorPreferencePage_basicsymbols_colors;
+
+ public static String RutaEditorPreferencePage_function_colors;
+
+ public static String RutaEditorPreferencePage_then_colors;
+
+ public static String RutaSmartTypingConfigurationBlock_smartPaste_full;
+
+ public static String RutaSmartTypingConfigurationBlock_smartPaste_simple;
+
+ public static String RutaSmartTypingConfigurationBlock_tabs_title;
+
+ public static String RutaSmartTypingConfigurationBlock_autoclose_title;
+
+ public static String TodoTaskDescription;
+
+ public static String BuilderResolveImports;
+
+ public static String BuilderImportByName;
+
+ public static String BuilderIgnoreDuplicateShortnames;
+
+ public static String ProjectClearOutput;
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaProjectPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaProjectPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaProjectPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaProjectPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.core.RutaCorePreferences;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * Preference page to manage preferences for the ide plugin.
+ */
+public class RutaProjectPreferencePage extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ private BooleanFieldEditor clearOutput;
+
+ public RutaProjectPreferencePage() {
+ setPreferenceStore(RutaIdePlugin.getDefault().getPreferenceStore());
+ setDescription("Project Management");
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ clearOutput = new BooleanFieldEditor(RutaCorePreferences.PROJECT_CLEAR_OUTPUT,
+ RutaPreferencesMessages.ProjectClearOutput, getFieldEditorParent());
+ addField(clearOutput);
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+
+}
\ No newline at end of file
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPropertyPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPropertyPage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPropertyPage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaPropertyPage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.
+*/
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+public class RutaPropertyPage extends PropertyPage {
+
+ @Override
+ protected Control createContents(Composite parent) {
+ return new Composite(parent, SWT.NONE);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingConfigurationBlock.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingConfigurationBlock.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingConfigurationBlock.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingConfigurationBlock.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,225 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.ui.RutaPreferenceConstants;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.dltk.internal.corext.util.Messages;
+import org.eclipse.dltk.ui.CodeFormatterConstants;
+import org.eclipse.dltk.ui.PreferenceConstants;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlock;
+import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore;
+import org.eclipse.dltk.ui.preferences.PreferencesMessages;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.Link;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+
+/**
+ * Configures Editor typing preferences.
+ */
+class RutaSmartTypingConfigurationBlock extends AbstractConfigurationBlock {
+
+ public RutaSmartTypingConfigurationBlock(OverlayPreferenceStore store) {
+ super(store);
+
+ store.addKeys(createOverlayStoreKeys());
+ }
+
+ private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
+
+ List keys = new ArrayList();
+
+ keys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_CLOSE_STRINGS));
+ keys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_CLOSE_BRACKETS));
+ keys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_CLOSE_BRACES));
+ keys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
+ PreferenceConstants.EDITOR_SMART_TAB));
+ keys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT,
+ RutaPreferenceConstants.EDITOR_SMART_PASTE_MODE));
+
+ return (OverlayPreferenceStore.OverlayKey[]) keys
+ .toArray(new OverlayPreferenceStore.OverlayKey[keys.size()]);
+ }
+
+ public Control createControl(Composite parent) {
+ Composite control = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ control.setLayout(layout);
+
+ Composite composite = createSubsection(control, null,
+ RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_autoclose_title);
+ addAutoclosingSection(composite);
+
+ composite = createSubsection(control, null,
+ RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_tabs_title);
+ addTabSection(composite);
+
+ composite = createSubsection(control, null,
+ PreferencesMessages.SmartTypingConfigurationBlock_pasting_title);
+ addPasteSection(composite);
+
+ return control;
+ }
+
+ private void addPasteSection(Composite composite) {
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+
+ String label = null;
+
+ label = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_smartPaste_simple;
+ addRadioButton(composite, label, RutaPreferenceConstants.EDITOR_SMART_PASTE_MODE,
+ RutaPreferenceConstants.EDITOR_SMART_PASTE_MODE_SIMPLE);
+
+ label = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_smartPaste_full;
+ addRadioButton(composite, label, RutaPreferenceConstants.EDITOR_SMART_PASTE_MODE,
+ RutaPreferenceConstants.EDITOR_SMART_PASTE_MODE_FULL);
+
+ }
+
+ private void addTabSection(Composite composite) {
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+
+ String label;
+ label = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_typing_smartTab;
+ addCheckBox(composite, label, PreferenceConstants.EDITOR_SMART_TAB, 0);
+
+ createMessage(composite);
+ }
+
+ private void addAutoclosingSection(Composite composite) {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ composite.setLayout(layout);
+
+ String label;
+
+ label = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_closeStrings;
+ addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_STRINGS, 0);
+
+ label = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_closeBrackets;
+ addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_BRACKETS, 0);
+
+ label = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_closeBraces;
+ addCheckBox(composite, label, PreferenceConstants.EDITOR_CLOSE_BRACES, 0);
+ }
+
+ private void createMessage(final Composite composite) {
+ // TODO create a link with an argument, so the formatter preference page
+ // can open the
+ // current profile automatically.
+ String linkTooltip = PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tooltip;
+ String text;
+ String indentMode = RutaIdePlugin.getDefault().getPreferenceStore()
+ .getString(CodeFormatterConstants.FORMATTER_TAB_CHAR);
+ if (CodeFormatterConstants.TAB.equals(indentMode))
+ text = Messages.format(
+ PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tab_text,
+ new String[] { Integer.toString(getTabDisplaySize()) });
+ else
+ text = Messages.format(
+ PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_others_text,
+ new String[] { Integer.toString(getTabDisplaySize()), getIndentMode() });
+
+ final Link link = new Link(composite, SWT.NONE);
+ link.setText(text);
+ link.setToolTipText(linkTooltip);
+ GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
+ gd.widthHint = 300; // don't get wider initially
+ link.setLayoutData(gd);
+ link.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ PreferencesUtil.createPreferenceDialogOn(link.getShell(),
+ "org.apache.uima.ruta.ide.ui.EditorPreferences", null, null); //$NON-NLS-1$
+ }
+ });
+
+ final IPreferenceStore combinedStore = getPreferenceStore();
+ final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
+ private boolean fHasRun = false;
+
+ public void propertyChange(PropertyChangeEvent event) {
+ if (fHasRun)
+ return;
+ if (composite.isDisposed())
+ return;
+ String property = event.getProperty();
+ if (CodeFormatterConstants.FORMATTER_TAB_CHAR.equals(property)
+ || CodeFormatterConstants.FORMATTER_TAB_SIZE.equals(property)) {
+ fHasRun = true;
+ link.dispose();
+ createMessage(composite);
+ Dialog.applyDialogFont(composite);
+ composite.redraw();
+ composite.layout();
+ }
+ }
+ };
+ combinedStore.addPropertyChangeListener(propertyChangeListener);
+ link.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
+ combinedStore.removePropertyChangeListener(propertyChangeListener);
+ }
+ });
+ }
+
+ private String getIndentMode() {
+ String indentMode = RutaIdePlugin.getDefault().getPreferenceStore()
+ .getString(CodeFormatterConstants.FORMATTER_TAB_CHAR);
+
+ if (CodeFormatterConstants.SPACE.equals(indentMode))
+ return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_spaces;
+
+ if (CodeFormatterConstants.TAB.equals(indentMode))
+ return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tabs;
+
+ if (CodeFormatterConstants.MIXED.equals(indentMode))
+ return PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tabsAndSpaces;
+
+ Assert.isTrue(false, "Illegal indent mode - must not happen"); //$NON-NLS-1$
+ return null;
+ }
+
+ private int getTabDisplaySize() {
+ return RutaIdePlugin.getDefault().getPreferenceStore()
+ .getInt(CodeFormatterConstants.FORMATTER_TAB_SIZE);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaSmartTypingPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -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.
+ */
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage;
+import org.eclipse.dltk.ui.preferences.IPreferenceConfigurationBlock;
+import org.eclipse.dltk.ui.preferences.OverlayPreferenceStore;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+
+public class RutaSmartTypingPreferencePage extends AbstractConfigurationBlockPreferencePage {
+
+ /*
+ * @see
+ * org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#setDescription()
+ */
+ @Override
+ protected void setDescription() {
+ String description = RutaPreferencesMessages.RutaSmartTypingConfigurationBlock_typing_tabTitle;
+ setDescription(description);
+ }
+
+ /*
+ * @seeorg.org.eclipse.ui.internal.editors.text.AbstractConfigurationBlockPreferencePage#
+ * setPreferenceStore()
+ */
+ @Override
+ protected void setPreferenceStore() {
+ setPreferenceStore(RutaIdePlugin.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ protected Label createDescriptionLabel(Composite parent) {
+ return null; // no description for new look.
+ }
+
+ /*
+ * @seeorg.eclipse.ui.internal.editors.text.AbstractConfigureationBlockPreferencePage#
+ * createConfigurationBlock(org.eclipse.ui.internal.editors.text.OverlayPreferenceStore)
+ */
+ @Override
+ protected IPreferenceConfigurationBlock createConfigurationBlock(
+ OverlayPreferenceStore overlayPreferenceStore) {
+ return new RutaSmartTypingConfigurationBlock(overlayPreferenceStore);
+ }
+
+ @Override
+ protected String getHelpId() {
+ return "";
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaTodoTaskPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaTodoTaskPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaTodoTaskPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/preferences/RutaTodoTaskPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.preferences;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.dltk.ui.PreferencesAdapter;
+import org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage;
+import org.eclipse.dltk.ui.preferences.AbstractOptionsBlock;
+import org.eclipse.dltk.ui.preferences.AbstractTodoTaskOptionsBlock;
+import org.eclipse.dltk.ui.preferences.PreferenceKey;
+import org.eclipse.dltk.ui.util.IStatusChangeListener;
+import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
+
+public class RutaTodoTaskPreferencePage extends
+ AbstractConfigurationBlockPropertyAndPreferencePage {
+
+ static final PreferenceKey CASE_SENSITIVE = AbstractTodoTaskOptionsBlock
+ .createCaseSensitiveKey(RutaIdePlugin.PLUGIN_ID);
+
+ static final PreferenceKey ENABLED = AbstractTodoTaskOptionsBlock
+ .createEnabledKey(RutaIdePlugin.PLUGIN_ID);
+
+ static final PreferenceKey TAGS = AbstractTodoTaskOptionsBlock
+ .createTagKey(RutaIdePlugin.PLUGIN_ID);
+
+ protected PreferenceKey[] getPreferenceKeys() {
+ return new PreferenceKey[] { TAGS, ENABLED, CASE_SENSITIVE };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage #getHelpId()
+ */
+ @Override
+ protected String getHelpId() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPreferencePage #setDescription()
+ */
+ @Override
+ protected void setDescription() {
+ setDescription(RutaPreferencesMessages.TodoTaskDescription);
+ }
+
+ protected Preferences getPluginPreferences() {
+ return RutaIdePlugin.getDefault().getPluginPreferences();
+ }
+
+ @Override
+ protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener,
+ IProject project, IWorkbenchPreferenceContainer container) {
+ return new AbstractTodoTaskOptionsBlock(newStatusChangedListener, project, getPreferenceKeys(),
+ container) {
+ @Override
+ protected PreferenceKey getTags() {
+ return TAGS;
+ }
+
+ @Override
+ protected PreferenceKey getEnabledKey() {
+ return ENABLED;
+ }
+
+ @Override
+ protected PreferenceKey getCaseSensitiveKey() {
+ return CASE_SENSITIVE;
+ }
+ };
+ }
+
+ @Override
+ protected String getNatureId() {
+ return RutaNature.NATURE_ID;
+ }
+
+ @Override
+ protected String getProjectHelpId() {
+ return null;
+ }
+
+ @Override
+ protected void setPreferenceStore() {
+ setPreferenceStore(new PreferencesAdapter(RutaIdePlugin.getDefault()
+ .getPluginPreferences()));
+ }
+
+ @Override
+ protected String getPreferencePageId() {
+ return "org.apache.uima.ruta.ide.preferences.todo";
+ }
+
+ @Override
+ protected String getPropertyPageId() {
+ return "org.apache.uima.ruta.ide.propertyPage.todo";
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/search/RutaSearchPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/search/RutaSearchPage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/search/RutaSearchPage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/search/RutaSearchPage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.search;
+
+import org.apache.uima.ruta.ide.core.RutaLanguageToolkit;
+import org.eclipse.dltk.core.IDLTKLanguageToolkit;
+import org.eclipse.dltk.ui.search.ScriptSearchPage;
+
+public class RutaSearchPage extends ScriptSearchPage {
+ @Override
+ protected IDLTKLanguageToolkit getLanguageToolkit() {
+ return RutaLanguageToolkit.getDefault();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaCodeTemplatesPreferencePage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaCodeTemplatesPreferencePage.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaCodeTemplatesPreferencePage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaCodeTemplatesPreferencePage.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.templates;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.apache.uima.ruta.ide.ui.RutaPartitions;
+import org.apache.uima.ruta.ide.ui.text.SimpleRutaSourceViewerConfiguration;
+import org.apache.uima.ruta.ide.ui.text.RutaTextTools;
+import org.eclipse.dltk.ui.templates.ScriptTemplateAccess;
+import org.eclipse.dltk.ui.templates.ScriptTemplatePreferencePage;
+import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * Ruta code templates preference page
+ */
+public class RutaCodeTemplatesPreferencePage extends ScriptTemplatePreferencePage {
+
+ /*
+ * @see
+ * org.eclipse.dltk.ui.templates.ScriptTemplatePreferencePage#createSourceViewerConfiguration()
+ */
+ @Override
+ protected ScriptSourceViewerConfiguration createSourceViewerConfiguration() {
+ return new SimpleRutaSourceViewerConfiguration(getTextTools().getColorManager(),
+ getPreferenceStore(), null, RutaPartitions.TM_PARTITIONING, false);
+ }
+
+ /*
+ * @see
+ * org.eclipse.dltk.ui.templates.ScriptTemplatePreferencePage#setDocumentParticioner(org.eclipse
+ * .jface.text.IDocument)
+ */
+ @Override
+ protected void setDocumentParticioner(IDocument document) {
+ getTextTools().setupDocumentPartitioner(document, RutaPartitions.TM_PARTITIONING);
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplatePreferencePage#setPreferenceStore()
+ */
+ @Override
+ protected void setPreferenceStore() {
+ setPreferenceStore(RutaIdePlugin.getDefault().getPreferenceStore());
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplatePreferencePage#getTemplateAccess()
+ */
+ @Override
+ protected ScriptTemplateAccess getTemplateAccess() {
+ return RutaTemplateAccess.getInstance();
+ }
+
+ private RutaTextTools getTextTools() {
+ return RutaIdePlugin.getDefault().getTextTools();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateAccess.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateAccess.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateAccess.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateAccess.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.templates;
+
+import org.apache.uima.ruta.ide.RutaIdePlugin;
+import org.eclipse.dltk.ui.templates.ScriptTemplateAccess;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Provides access to Ruta template store.
+ */
+public class RutaTemplateAccess extends ScriptTemplateAccess {
+ // Template
+ private static final String CUSTOM_TEMPLATES_KEY = "org.eclipse.ruta.Templates";
+
+ private static RutaTemplateAccess instance;
+
+ public static RutaTemplateAccess getInstance() {
+ if (instance == null) {
+ instance = new RutaTemplateAccess();
+ }
+
+ return instance;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplateAccess#getContextTypeId()
+ */
+ @Override
+ protected String getContextTypeId() {
+ return RutaUniversalTemplateContextType.CONTEXT_TYPE_ID;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplateAccess#getCustomTemplatesKey()
+ */
+ @Override
+ protected String getCustomTemplatesKey() {
+ return CUSTOM_TEMPLATES_KEY;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplateAccess#getPreferenceStore()
+ */
+ @Override
+ protected IPreferenceStore getPreferenceStore() {
+ return RutaIdePlugin.getDefault().getPreferenceStore();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateCompletionProcessor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateCompletionProcessor.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateCompletionProcessor.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateCompletionProcessor.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,54 @@
+/*
+ * 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.
+*/
+
+package org.apache.uima.ruta.ide.ui.templates;
+
+import org.eclipse.dltk.ui.templates.ScriptTemplateAccess;
+import org.eclipse.dltk.ui.templates.ScriptTemplateCompletionProcessor;
+import org.eclipse.dltk.ui.text.completion.ScriptContentAssistInvocationContext;
+
+public class RutaTemplateCompletionProcessor extends ScriptTemplateCompletionProcessor {
+
+ private static char[] IGNORE = new char[] { '.' };
+
+ public RutaTemplateCompletionProcessor(ScriptContentAssistInvocationContext context) {
+ super(context);
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplateCompletionProcessor#getContextTypeId()
+ */
+ @Override
+ protected String getContextTypeId() {
+ return RutaUniversalTemplateContextType.CONTEXT_TYPE_ID;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.templates.ScriptTemplateCompletionProcessor#getTemplateAccess()
+ */
+ @Override
+ protected ScriptTemplateAccess getTemplateAccess() {
+ return RutaTemplateAccess.getInstance();
+ }
+
+ @Override
+ protected char[] getIgnore() {
+ return IGNORE;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateContext.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateContext.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateContext.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaTemplateContext.java Mon Apr 29 14:50:56 2013
@@ -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.
+*/
+
+package org.apache.uima.ruta.ide.ui.templates;
+
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.ui.templates.ScriptTemplateContext;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.templates.TemplateContextType;
+
+public class RutaTemplateContext extends ScriptTemplateContext {
+
+ public RutaTemplateContext(TemplateContextType type, IDocument document,
+ int completionOffset, int completionLength, ISourceModule sourceModule) {
+ super(type, document, completionOffset, completionLength, sourceModule);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaUniversalTemplateContextType.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaUniversalTemplateContextType.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaUniversalTemplateContextType.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/templates/RutaUniversalTemplateContextType.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.
+*/
+
+package org.apache.uima.ruta.ide.ui.templates;
+
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.ui.templates.ScriptTemplateContext;
+import org.eclipse.dltk.ui.templates.ScriptTemplateContextType;
+import org.eclipse.jface.text.IDocument;
+
+public class RutaUniversalTemplateContextType extends ScriptTemplateContextType {
+ public static final String CONTEXT_TYPE_ID = "tmUniversalTemplateContextType";
+
+ public RutaUniversalTemplateContextType() {
+ // empty constructor
+ }
+
+ public RutaUniversalTemplateContextType(String id) {
+ super(id);
+ }
+
+ public RutaUniversalTemplateContextType(String id, String name) {
+ super(id, name);
+ }
+
+ @Override
+ public ScriptTemplateContext createContext(IDocument document, int offset, int length,
+ ISourceModule sourceModule) {
+ return new RutaTemplateContext(this, document, offset, length, sourceModule);
+ }
+}
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlink.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlink.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlink.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlink.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.ui.text;
+package org.apache.uima.ruta.ide.ui.text;
import org.eclipse.core.resources.IFile;
import org.eclipse.dltk.internal.ui.editor.DLTKEditorMessages;
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlinkDetector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlinkDetector.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlinkDetector.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/ExternalTypeHyperlinkDetector.java Mon Apr 29 14:50:56 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.ui.text;
+package org.apache.uima.ruta.ide.ui.text;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -32,12 +32,12 @@ import org.apache.uima.UIMAFramework;
import org.apache.uima.resource.ResourceManager;
import org.apache.uima.resource.metadata.TypeDescription;
import org.apache.uima.resource.metadata.TypeSystemDescription;
-import org.apache.uima.textmarker.ide.core.builder.TextMarkerProjectUtils;
-import org.apache.uima.textmarker.ide.core.codeassist.TextMarkerReferenceVisitor;
-import org.apache.uima.textmarker.ide.core.codeassist.TextMarkerSelectionParser;
-import org.apache.uima.textmarker.ide.parser.ast.TMTypeConstants;
-import org.apache.uima.textmarker.ide.parser.ast.TextMarkerModuleDeclaration;
-import org.apache.uima.textmarker.ide.parser.ast.TextMarkerVariableReference;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.apache.uima.ruta.ide.core.codeassist.RutaReferenceVisitor;
+import org.apache.uima.ruta.ide.core.codeassist.RutaSelectionParser;
+import org.apache.uima.ruta.ide.parser.ast.TMTypeConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaModuleDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaVariableReference;
import org.apache.uima.util.InvalidXMLException;
import org.apache.uima.util.XMLInputSource;
import org.eclipse.core.resources.IFile;
@@ -87,24 +87,24 @@ public class ExternalTypeHyperlinkDetect
if (input instanceof ISourceModule) {
ISourceModule sm = (ISourceModule) input;
IModelElement modelElement = sm.getModelElement();
- TextMarkerSelectionParser parser = new TextMarkerSelectionParser();
+ RutaSelectionParser parser = new RutaSelectionParser();
ModuleDeclaration moduleDeclaration = parser.parse(sm);
String word = document.get(wordRegion.getOffset(), wordRegion.getLength());
- TextMarkerReferenceVisitor referenceVisitor = new TextMarkerReferenceVisitor(wordRegion
+ RutaReferenceVisitor referenceVisitor = new RutaReferenceVisitor(wordRegion
.getOffset());
moduleDeclaration.traverse(referenceVisitor);
ASTNode node = referenceVisitor.getResult();
- if (node instanceof TextMarkerVariableReference
- && moduleDeclaration instanceof TextMarkerModuleDeclaration) {
- TextMarkerVariableReference vr = (TextMarkerVariableReference) node;
- TextMarkerModuleDeclaration parsed = (TextMarkerModuleDeclaration) moduleDeclaration;
+ if (node instanceof RutaVariableReference
+ && moduleDeclaration instanceof RutaModuleDeclaration) {
+ RutaVariableReference vr = (RutaVariableReference) node;
+ RutaModuleDeclaration parsed = (RutaModuleDeclaration) moduleDeclaration;
if (vr.getType() == TMTypeConstants.TM_TYPE_AT) {
String nodeText = vr.getStringRepresentation();
Collection<String> importedTypeSystems = parsed.descriptorInfo.getImportedTypeSystems();
List<IHyperlink> result = new ArrayList<IHyperlink>();
for (String tsString : importedTypeSystems) {
IFolder folder = modelElement.getScriptProject().getProject().getFolder(
- TextMarkerProjectUtils.getDefaultDescriptorLocation());
+ RutaProjectUtils.getDefaultDescriptorLocation());
String xmlFilePath = tsString.replaceAll("\\.", "/");
xmlFilePath = xmlFilePath.substring(0, xmlFilePath.length()) + ".xml";
Set<String> types = getTypes(folder, xmlFilePath);
Modified: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/Messages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/Messages.java?rev=1477113&r1=1477112&r2=1477113&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/Messages.java (original)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/Messages.java Mon Apr 29 14:50:56 2013
@@ -17,14 +17,14 @@
* under the License.
*/
-package org.apache.uima.textmarker.ide.ui.text;
+package org.apache.uima.ruta.ide.ui.text;
import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
- private static final String BUNDLE_NAME = "org.apache.uima.textmarker.ide.ui.text.messages"; //$NON-NLS-1$
+ private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.ui.text.messages"; //$NON-NLS-1$
- public static String TextMarkerRequirePackageMarkerResolution_addPackageToBuildpath;
+ public static String RutaRequirePackageMarkerResolution_addPackageToBuildpath;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaAutoEditStrategy.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaAutoEditStrategy.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaAutoEditStrategy.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaAutoEditStrategy.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,919 @@
+/*
+ * 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.
+ */
+
+package org.apache.uima.ruta.ide.ui.text;
+
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.uima.ruta.ide.ui.RutaPartitions;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.ui.CodeFormatterConstants;
+import org.eclipse.dltk.ui.PreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.DocumentRewriteSession;
+import org.eclipse.jface.text.DocumentRewriteSessionType;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.TextUtilities;
+import org.eclipse.jface.text.rules.FastPartitioner;
+
+public class RutaAutoEditStrategy extends DefaultIndentLineAutoEditStrategy {
+ // TODO
+ IPreferenceStore fStore;
+
+ String fPartitioning;
+
+ final int maxCharsAway = 100;
+
+ public RutaAutoEditStrategy(IPreferenceStore store, String part) {
+ fStore = store;
+ fPartitioning = part;
+ }
+
+ /*
+ * possible prefereces:
+ *
+ * general indent on/off smart tab key behaviour autoclose "strings", 'strings' autoclose
+ * {brackets}, [], () smart paste
+ */
+
+ private boolean isSmartTab() {
+ return fStore.getBoolean(PreferenceConstants.EDITOR_SMART_TAB);
+ }
+
+ private boolean isSmartMode() {
+ return fStore.getBoolean(PreferenceConstants.EDITOR_SMART_INDENT);
+ }
+
+ private boolean closeBrackets() {
+ return fStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_BRACKETS);
+ }
+
+ private boolean isSmartPaste() {
+ return fStore.getBoolean(PreferenceConstants.EDITOR_SMART_PASTE);
+ }
+
+ private boolean closeStrings() {
+ return fStore.getBoolean(PreferenceConstants.EDITOR_CLOSE_STRINGS);
+ }
+
+ private int getIndentSize() {
+ return fStore.getInt(CodeFormatterConstants.FORMATTER_INDENTATION_SIZE);
+ }
+
+ private String getTabStyle() {
+ return fStore.getString(CodeFormatterConstants.FORMATTER_TAB_CHAR);
+ }
+
+ private String getIndent() {
+ if (getTabStyle().equals(CodeFormatterConstants.SPACE)) {
+ int size = getIndentSize();
+ String res = "";
+ for (int i = 0; i < size; i++)
+ res += " ";
+ return res;
+ } else
+ return "\t";
+ }
+
+ private boolean isLineDelimiter(IDocument document, String text) {
+ String[] delimiters = document.getLegalLineDelimiters();
+ if (delimiters != null)
+ return TextUtilities.equals(delimiters, text) > -1;
+ return false;
+ }
+
+ /**
+ * Returns the leading whitespaces and tabs.
+ *
+ * @param document
+ * - the document being parsed
+ * @param line
+ * - the line being searched
+ * @return the leading whitespace
+ * @throws BadLocationException
+ * in case <code>line</code> is invalid in the document
+ */
+ private String getLineIndent(IDocument document, int line) throws BadLocationException {
+ if (line > -1) {
+ int start = document.getLineOffset(line);
+ int end = start + document.getLineLength(line); // was - 1
+ int whiteend = findEndOfWhiteSpace(document, start, end);
+ return document.get(start, whiteend - start);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the leading whitespaces and tabs.
+ *
+ * @param line
+ * - the line being searched
+ * @return the leading whitespace
+ */
+ public String getLineIndent(String line) {
+ int end = line.length();
+ int whiteend = end;
+ int offset = 0;
+ while (offset < end) {
+ char c = line.charAt(offset);
+ if (c != ' ' && c != '\t') {
+ whiteend = offset;
+ break;
+ }
+ offset++;
+ }
+ return line.substring(0, whiteend);
+ }
+
+ /**
+ * Find line with number <=line, that is not empty and is not a comment line starting with #
+ *
+ * @param d
+ * the document to search in
+ * @param line
+ * number of starting line
+ * @return number of code line or -1 if no such line found
+ * @throws BadLocationException
+ */
+ private int getLastNonEmptyLine(IDocument d, int line) throws BadLocationException {
+ int res = line;
+
+ while (res > -1) {
+ String str = getDocumentLine(d, res).trim();
+ if ((!str.startsWith("#")) && str.length() > 0)
+ return res;
+ res--;
+ }
+
+ return res;
+ }
+
+ /**
+ * Fetched line from document
+ *
+ * @param d
+ * the document
+ * @param line
+ * number of req. line
+ * @return string with line
+ * @throws BadLocationException
+ * if <b>line</b> is not correct line number
+ */
+ public String getDocumentLine(IDocument d, int line) throws BadLocationException {
+ int start = d.getLineOffset(line);
+ int length = d.getLineLength(line);
+ return d.get(start, length);
+ }
+
+ /**
+ * Get partition type covering offset
+ *
+ * @param d
+ * @param offset
+ * @return
+ * @throws BadLocationException
+ */
+ private String getRegionType(IDocument d, int offset) throws BadLocationException {
+ int p = ((offset == d.getLength()) ? offset - 1 : offset);
+ ITypedRegion region = TextUtilities.getPartition(d, fPartitioning, p, true);
+ return region.getType();
+ }
+
+ /**
+ * Searchs an pair from offset, forward of backwards. Can skip strings and comments (uses
+ * ruta partitioning).
+ *
+ * @param d
+ * @param offset
+ * @param forward
+ * @param opening
+ * @param closing
+ * @param skipCommentLines
+ * @param skipStrings
+ * @return offset of pair, or -1 if not found
+ * @throws BadLocationException
+ */
+ private int searchPair(IDocument d, int offset, boolean forward, char opening, char closing,
+ boolean skipCommentLines, boolean skipStrings) throws BadLocationException {
+ int deep = 0;
+ int i = offset;
+ if (forward) {
+ while (i < d.getLength()) {
+ ITypedRegion region = TextUtilities.getPartition(d, fPartitioning, i, true);
+ if (region.getType() == RutaPartitions.TM_COMMENT && skipCommentLines) {
+ i = region.getOffset() + region.getLength();
+ continue;
+ }
+ if (region.getType() == RutaPartitions.TM_STRING && skipStrings) {
+ i = region.getOffset() + region.getLength();
+ continue;
+ }
+ char c = d.getChar(i);
+ if (c == opening)
+ deep++;
+ if (c == closing) {
+ if (deep == 0)
+ return i;
+ deep--;
+ }
+ i++;
+ if (i - offset > maxCharsAway)
+ return -1;
+ }
+ } else {
+ while (i >= 0) {
+ ITypedRegion region = TextUtilities.getPartition(d, fPartitioning, i, true);
+ if (region.getType() == RutaPartitions.TM_COMMENT && skipCommentLines) {
+ i = region.getOffset() - 1;
+ continue;
+ }
+ if (region.getType() == RutaPartitions.TM_STRING && skipStrings) {
+ i = region.getOffset() - 1;
+ continue;
+ }
+ char c = d.getChar(i);
+ if (c == closing)
+ deep++;
+ if (c == opening) {
+ if (deep == 0)
+ return i;
+ deep--;
+ }
+ i--;
+ if (offset - i > maxCharsAway)
+ return -1;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Finds line < <b>line</b>, such the indent of it is less than of <b>line</b>
+ *
+ * @param d
+ * the document to search in
+ * @param line
+ * appropriate line number
+ * @return if found, number < <b>line</b>, else <b>line</b>
+ */
+ private int findIndentStart(IDocument d, int line) throws BadLocationException {
+ String curIndent = getLineIndent(d, line);
+ int curIndentLength = getPhysicalLength(curIndent);
+ int cur = line - 1;
+ while (cur >= 0) {
+ String curLine = getDocumentLine(d, cur);
+ String ind = getLineIndent(d, cur);
+ if ((!curLine.trim().startsWith("#")) && getPhysicalLength(ind) < curIndentLength)
+ return cur;
+ cur--;
+ }
+ return line;
+ }
+
+ /**
+ * Calculates real length of string. So any char except \t has length 1, \t has length 8.
+ *
+ * @param str
+ * string to process
+ * @return length
+ */
+ public int getPhysicalLength(String str) {
+ int res = 0;
+ for (int i = 0; i < str.length(); i++) {
+ if (str.charAt(i) == '\t')
+ res += 8; // TODO
+ else
+ res++;
+ }
+ return res;
+ }
+
+ /**
+ * Return pair to brace. Ex. '(' for ')', e.t.c.
+ *
+ * @param b
+ * input brace
+ * @return peer brace
+ */
+ private char getBracePair(char b) {
+ switch (b) {
+ case '(':
+ return ')';
+ case ')':
+ return '(';
+ case '[':
+ return ']';
+ case ']':
+ return '[';
+ case '{':
+ return '}';
+ case '}':
+ return '{';
+ case '\"':
+ return '\"';
+ case '\'':
+ return '\'';
+ }
+ return b;
+ }
+
+ /**
+ * Installs a partitioner with <code>document</code>.
+ *
+ * @param document
+ * the document
+ */
+ private static void installStuff(Document document) {
+ String[] types = new String[] { RutaPartitions.TM_STRING,
+ RutaPartitions.TM_COMMENT, IDocument.DEFAULT_CONTENT_TYPE };
+ FastPartitioner partitioner = new FastPartitioner(new RutaPartitionScanner(), types);
+ partitioner.connect(document);
+ document.setDocumentPartitioner(RutaPartitions.TM_PARTITIONING, partitioner);
+ }
+
+ /**
+ * Removes partitioner with <code>document</code>.
+ *
+ * @param document
+ * the document
+ */
+ private static void removeStuff(Document document) {
+ document.setDocumentPartitioner(RutaPartitions.TM_PARTITIONING, null);
+ }
+
+ /**
+ * STRATEGIES
+ */
+
+ /**
+ * Main indenting algorithm. Needs correct partitioning to work.
+ *
+ * @param d
+ * the processed document
+ * @param line
+ * line, indenting of which we wanna know
+ * @param newLine
+ * if <b>line</b> is new line, so we have pressed enter-key, and need indentation for new
+ * line
+ * @param offset
+ * position, where we have jumped to new line
+ * @return correct indent for line, or null if we should use "default" indent. So calling side
+ * should determine, change indent or not, or may be use indent of previous line.
+ * @throws BadLocationException
+ */
+ private String calcLineIndent(IDocument d, int line, boolean newLine, int offset)
+ throws BadLocationException {
+
+ boolean isDocumentEnd = (offset == d.getLength());
+
+ // STRINGS
+ if (newLine) {
+ // if we wrap string
+ if (getRegionType(d, offset) == RutaPartitions.TM_STRING) {
+ int realLine = d.getLineOfOffset(offset);
+ String curIndent = getLineIndent(d, realLine);
+ // if we just closed string
+ if (d.getChar(offset - 1) != '"') {
+ // if we are fully in string
+ if (getRegionType(d, d.getLineOffset(realLine)) == RutaPartitions.TM_STRING) {
+ return curIndent;
+ }
+ // if we first time wrap string
+ return curIndent + getIndent();
+ }
+ }
+ } else {
+ // don't correct strings
+ if (getRegionType(d, d.getLineOffset(line)) == RutaPartitions.TM_STRING) {
+ return getLineIndent(d, line); // notice, that we don't use
+ // null
+ }
+ }
+
+ // LINE JOINING
+ if (newLine) {
+ int realLine = d.getLineOfOffset(offset);
+ if (line > 0) {
+ String previousLine = "";
+ if (realLine == line - 1) {
+ int start = d.getLineOffset(realLine);
+ previousLine = d.get(start, offset - start);
+ } else
+ previousLine = getDocumentLine(d, line - 1);
+ if (previousLine.trim().endsWith("\\")) {
+ String prePreviousLine = getDocumentLine(d, line - 2);
+ if (prePreviousLine.trim().endsWith("\\"))
+ return getLineIndent(d, line - 1);
+ return getLineIndent(d, line - 1) + getIndent() + getIndent();
+ }
+ if (line > 1) {
+ String prePreviousLine = getDocumentLine(d, line - 2);
+ if (prePreviousLine.trim().endsWith("\\")) {
+ // find start
+ int t = line - 2;
+ while (t > 0 && getDocumentLine(d, t - 1).trim().endsWith("\\")) {
+ t--;
+ }
+ return getLineIndent(d, t);
+ }
+ }
+ }
+ } else {
+ /*
+ * If this line is explicitly joined: If the previous line was also joined, line it up with
+ * that one, otherwise add two 'shiftwidth'
+ */
+ if (line > 0) {
+ String previousLine = getDocumentLine(d, line - 1);
+ if (previousLine.trim().endsWith("\\")) {
+ if (line > 1) {
+ String prePreviousLine = getDocumentLine(d, line - 2);
+ if (prePreviousLine.trim().endsWith("\\"))
+ return getLineIndent(d, line - 1);
+ }
+ return getLineIndent(d, line - 1) + getIndent() + getIndent();
+ }
+ }
+ }
+
+ // Search backwards for the previous non-empty line.
+ int lastNonEmptyLine = getLastNonEmptyLine(d, line - 1);
+
+ if (lastNonEmptyLine < 0) {
+ // This is the first non-empty line, use zero indent.
+ return "";
+ }
+
+ // first check, if we not inside string, if yes, jump to start
+ ITypedRegion region = TextUtilities.getPartition(d, fPartitioning,
+ d.getLineOffset(lastNonEmptyLine), true);
+ if (region.getType() == RutaPartitions.TM_STRING) {
+ lastNonEmptyLine = d.getLineOfOffset(region.getOffset());
+ }
+
+ // If the previous line is inside parenthesis, use the indent of the
+ // starting line.
+ int plnumstart;
+ String previousLineIndent = "";
+ int pairOffset = searchPair(d, d.getLineOffset(lastNonEmptyLine), false, '(', ')', true, true);
+
+ if (pairOffset >= 0) {
+ plnumstart = d.getLineOfOffset(pairOffset);
+ previousLineIndent = getLineIndent(d, plnumstart);
+ } else {
+ plnumstart = lastNonEmptyLine;
+ previousLineIndent = getLineIndent(d, lastNonEmptyLine);
+ }
+
+ /*
+ * When inside parenthesis: If at the first line below the parenthesis add two 'shiftwidth',
+ * otherwise same as previous line. i = (a + b + c)
+ */
+ int p = searchPair(d, offset - 1, false, '(', ')', true, true);
+ if (p >= 0) {
+ if (d.getLineOfOffset(p) == lastNonEmptyLine) {
+ // When the start is inside parenthesis, only indent one
+ // 'shiftwidth'.
+ int pp = searchPair(d, p, false, '(', ')', true, true);
+ if (pp >= 0)
+ return getLineIndent(d, lastNonEmptyLine) + getIndent();
+ return getLineIndent(d, lastNonEmptyLine) + getIndent() + getIndent();
+ }
+ if (d.getLineOfOffset(p) == plnumstart) {
+ return getLineIndent(d, lastNonEmptyLine);
+ }
+ if (d.getLineOfOffset(p) == line && !newLine)
+ return null;
+ return previousLineIndent;
+ }
+
+ // Get the line and remove a trailing comment.
+
+ String pline = "";
+ if (lastNonEmptyLine == line - 1 && newLine) {
+ pline = d.get(d.getLineOffset(line - 1), offset - d.getLineOffset(line - 1));
+ } else {
+ pline = getDocumentLine(d, lastNonEmptyLine);
+ }
+ int plineLen = pline.length();
+ int i;
+ for (i = 0; i < plineLen; i++) {
+ if (pline.charAt(i) == '#') {
+ pline = pline.substring(0, i);
+ break;
+ }
+ }
+
+ String plineTrimmed = pline.trim();
+
+ try {// If the current line begins with a keyword that lines up with
+ // "try"
+ String curLine = "";
+ if (lastNonEmptyLine == line - 1 && newLine) {
+ curLine = d.get(offset, d.getLineLength(line - 1) + d.getLineOffset(line - 1) - offset);
+ } else {
+ curLine = getDocumentLine(d, line).trim();
+ }
+
+ if (curLine.startsWith("except") || curLine.startsWith("finally")) {
+ int lnum = line - 1;
+
+ while (lnum >= 0) {
+ String temp = getDocumentLine(d, lnum).trim();
+ if (temp.startsWith("try") || temp.startsWith("except")) {
+ String ind = getLineIndent(d, lnum);
+ return ind;
+ }
+ lnum--;
+ }
+ // no mathing "try"
+ // System.out.println ("No matching 'try'!");
+ return null;
+ }
+
+ // If the current line begins with a header keyword, dedent
+ if (curLine.startsWith("elif") || curLine.startsWith("else")) {
+
+ // Unless the previous line was a one-liner
+ String temp = getDocumentLine(d, lastNonEmptyLine).trim();
+ if (temp.startsWith("for") || temp.startsWith("if") || temp.startsWith("try")
+ || temp.startsWith("while")) {
+ return previousLineIndent;
+ }
+ int sline = findIndentStart(d, lastNonEmptyLine);
+ String reqIndent = getLineIndent(d, sline);
+ return reqIndent;
+ }
+
+ } catch (BadLocationException e) {
+ // do nothing, we just don't have current line
+ }
+
+ // If the previous line was a stop-execution statement...
+ String regex = "^\\s*(break|continue|raise|pass|return)(\\s+.*$|$)";
+ if (Pattern.matches(regex, plineTrimmed)) {
+ // find indent
+ int sline = findIndentStart(d, lastNonEmptyLine);
+ String reqIndent = getLineIndent(d, sline);
+ if (newLine || isDocumentEnd
+ || (getPhysicalLength(getLineIndent(d, line)) > getPhysicalLength(reqIndent))) {
+ return reqIndent;
+ }
+ // trust the user
+ return null;
+ }
+
+ // If the previous line ended with a colon, indent this line
+ if (plineTrimmed.endsWith(":"))
+ return previousLineIndent + getIndent();
+
+ if (pairOffset >= 0 && newLine) {
+ return previousLineIndent;
+ }
+
+ // after-string
+ int prevLine = getLastNonEmptyLine(d, line - 1);
+ if (getRegionType(d, d.getLineOffset(prevLine)) == RutaPartitions.TM_STRING)
+ return previousLineIndent;
+
+ return null;
+ }
+
+ /**
+ * If we have pressed ":" for example, than we need to reindent line. This function changes
+ * document and sets correct indent for current line.
+ *
+ * @param d
+ * @param c
+ */
+ private void reindent(IDocument d, DocumentCommand c) {
+ try {
+ if (getRegionType(d, c.offset) != IDocument.DEFAULT_CONTENT_TYPE)
+ return;
+ int line = d.getLineOfOffset(c.offset);
+ String newIndent = calcLineIndent(d, line, false, c.offset);
+ if (newIndent == null)
+ return;
+ String curIndent = getLineIndent(d, line);
+ if (getPhysicalLength(curIndent) < getPhysicalLength(newIndent))
+ return;
+ d.replace(d.getLineOffset(line), curIndent.length(), newIndent);
+ c.offset += (newIndent.length() - curIndent.length());
+ } catch (BadLocationException e) {
+ }
+ }
+
+ /**
+ * Processes command in work with brackets, strings, etc
+ *
+ * @param d
+ * @param c
+ */
+ private void autoClose(IDocument d, DocumentCommand c) {
+ if (c.offset == -1)
+ return;
+ try {
+ if (d.getChar(c.offset - 1) == '\\')
+ return;
+ } catch (BadLocationException e1) {
+ }
+ if ('\"' == c.text.charAt(0) && !closeStrings())
+ return;
+ if ('\'' == c.text.charAt(0) && !closeStrings())
+ return;
+ if (!closeBrackets()
+ && ('[' == c.text.charAt(0) || '(' == c.text.charAt(0) || '{' == c.text.charAt(0)))
+ return;
+ try {
+
+ switch (c.text.charAt(0)) {
+ case '\"':
+ case '\'':
+ // if we close existing quote, do nothing
+ if ('\"' == c.text.charAt(0) && c.offset > 0 && "\"".equals(d.get(c.offset - 1, 1)))
+ return;
+
+ if ('\'' == c.text.charAt(0) && c.offset > 0 && "\'".equals(d.get(c.offset - 1, 1)))
+ return;
+
+ if (c.offset != d.getLength() && c.text.charAt(0) == d.get(c.offset, 1).charAt(0))
+ c.text = "";
+ else {
+ c.text += c.text;
+ c.length = 0;
+ }
+
+ c.shiftsCaret = false;
+ c.caretOffset = c.offset + 1;
+ break;
+ case '(':
+ case '{':
+ case '[':
+ // check partition
+ if (getRegionType(d, c.offset) != IDocument.DEFAULT_CONTENT_TYPE)
+ return;
+ if (c.offset != d.getLength() && c.text.charAt(0) == d.get(c.offset, 1).charAt(0))
+ return;
+
+ try { // in class closing
+ String regex = "^\\s*class\\s+.*";
+ String regex2 = ".*\\(.*\\).*";
+ int start = d.getLineOffset(d.getLineOfOffset(c.offset));
+ String curLine = d.get(start, c.offset - start);
+ if (Pattern.matches(regex, curLine) && !Pattern.matches(regex2, curLine)) {
+ c.text = "():";
+ c.shiftsCaret = false;
+ c.caretOffset = c.offset + 1;
+ return;
+ }
+ } catch (BadLocationException e) {
+ }
+
+ // add closing peer
+ c.text = c.text + getBracePair(c.text.charAt(0));
+ c.length = 0;
+
+ c.shiftsCaret = false;
+ c.caretOffset = c.offset + 1;
+ break;
+ case '}':
+ case ']':
+ case ')':
+ // check partition
+ if (getRegionType(d, c.offset) != IDocument.DEFAULT_CONTENT_TYPE)
+ return;
+ if (!closeBrackets())
+ return;
+ // if we already have bracket we should jump over it
+ if (c.offset != d.getLength() && c.text.charAt(0) == d.get(c.offset, 1).charAt(0)) {
+ c.text = "";
+ c.shiftsCaret = false;
+ c.caretOffset = c.offset + 1;
+ return;
+ }
+ break;
+ }
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * When we have pressed \t, sometimes we wanna not to tabulate, and jump to correct line start
+ * position.
+ *
+ * @param d
+ * @param c
+ * @return
+ */
+ private boolean smartIndentJump(IDocument d, DocumentCommand c) {
+ if (c.offset == -1 || d.getLength() == 0)
+ return false;
+ try {
+ // int p = (c.offset == d.getLength() ? c.offset - 1 : c.offset);
+ int line = d.getLineOfOffset(c.offset);
+ int start = d.getLineOffset(line);
+ // calculate indentation of this line
+ String resultIndent = calcLineIndent(d, line, false, start);
+ String currentIndent = getLineIndent(d, line);
+ if (resultIndent == null) { // we should save indentation
+ String curLine = getDocumentLine(d, line);
+ if (curLine.trim().length() > 0) // if indentation is "real",
+ // use it
+ resultIndent = currentIndent;
+ else {
+ // get current block level
+ int pl = getLastNonEmptyLine(d, line - 1); // find last
+ // code line
+ if (pl >= 0) {
+ String plStr = getDocumentLine(d, pl).trim();
+ // simple indent-guess strategy
+ String regex = "^\\s*(break|continue|raise|pass|return)(\\s+.*$|$)";
+ if (plStr.endsWith(":"))
+ resultIndent = getLineIndent(plStr) + getIndent();
+ else if (Pattern.matches(regex, plStr)) {
+ // find indent
+ int sline = findIndentStart(d, pl);
+ resultIndent = getLineIndent(d, sline);
+ } else
+ resultIndent = getLineIndent(d, pl);
+ } else
+ return false; // no indent is applicable, do nothing
+ }
+ }
+
+ if (c.offset >= start + resultIndent.length())
+ return false; // we already in the place
+
+ if (!currentIndent.startsWith(resultIndent)) { // create indent
+ c.offset = start;
+ c.length = currentIndent.length();
+ c.shiftsCaret = false;
+ c.text = resultIndent;
+ c.caretOffset = d.getLineOffset(line) + resultIndent.length();
+ return true;
+ }
+
+ c.length = 0;
+ c.shiftsCaret = false;
+ c.text = "";
+ c.caretOffset = d.getLineOffset(line) + resultIndent.length();
+ return true;
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ /**
+ * Reindents c.text when pasting.
+ *
+ * @param d
+ * @param c
+ */
+ private void smartPaste(IDocument d, DocumentCommand c) {
+ try {
+ String content = d.get(0, c.offset) + c.text;
+ Document temp = new Document(content);
+ DocumentRewriteSession session = temp
+ .startRewriteSession(DocumentRewriteSessionType.STRICTLY_SEQUENTIAL);
+ installStuff(temp);
+ int offset = c.offset;
+ int line = temp.getLineOfOffset(offset);
+ String lastIndent = getLineIndent(temp, line);
+ int firstLineOffset = temp.getLineOffset(line);
+ String commonIndent = temp.get(firstLineOffset, c.offset - firstLineOffset);
+ if(StringUtils.isNotBlank(commonIndent)) {
+ // do not copy non whitespace content as indent
+ // and only use leading white spaces
+ String notWSContent = commonIndent.replaceAll("^\\s+", "");
+ commonIndent = StringUtils.removeEnd(commonIndent, notWSContent);
+ }
+ line++;
+ try {
+ while (getDocumentLine(temp, line).trim().length() == 0)
+ line++;
+ offset = temp.getLineOffset(line);
+ } catch (BadLocationException e) {
+ offset = temp.getLength();
+ }
+ while (offset < temp.getLength()) {
+ String resultIndent = calcLineIndent(temp, line, false, temp.getLineOffset(line));
+ String currentIndent = getLineIndent(temp, line);
+ if (resultIndent == null) {
+ resultIndent = commonIndent + currentIndent;
+ // TODO commented to retain indent of pasted blocks
+ // if (getPhysicalLength(resultIndent) > getPhysicalLength(lastIndent))
+ // resultIndent = lastIndent;
+ }
+ temp.replace(offset, currentIndent.length(), resultIndent);
+ String currentLine = getDocumentLine(temp, line);
+ if (currentLine.trim().length() > 0 && (!currentLine.trim().startsWith("//"))) {
+ lastIndent = resultIndent;
+ }
+
+ if (temp.getLineOffset(line) + temp.getLineLength(line) == temp.getLength())
+ break;
+ line++;
+ offset = temp.getLineOffset(line);
+ }
+ temp.stopRewriteSession(session);
+ removeStuff(temp);
+ c.text = temp.get(c.offset, temp.getLength() - c.offset);
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument
+ * , org.eclipse.jface.text.DocumentCommand)
+ */
+ @Override
+ public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
+ if (c.doit == false)
+ return;
+ if (c.length == 0 && c.text != null && isLineDelimiter(d, c.text)) {
+ if (!isSmartMode()) {
+ super.customizeDocumentCommand(d, c);
+ return;
+ }
+ try {
+ String indent = calcLineIndent(d, d.getLineOfOffset(c.offset) + 1, true, c.offset);
+ if (indent == null)
+ super.customizeDocumentCommand(d, c);
+ else {
+ if (DLTKCore.DEBUG) {
+ System.err.println("Bug:PTN-9");
+ }
+ // if (c.offset - 1 >= 0 &&
+ // d.getChar(c.offset - 1) != '"' &&
+ // getRegionType(d, c.offset - 1) ==
+ // RutaPartitions.TM_STRING)
+ // c.text = "\\" + c.text + indent;
+ // else {
+ c.text = c.text + indent;
+ // }
+ }
+ } catch (BadLocationException e) {
+ super.customizeDocumentCommand(d, c);
+ }
+ return;
+ } else {
+ if (c.length <= 1 && c.text.length() == 1) {
+ switch (c.text.charAt(0)) {
+ case ':':
+ reindent(d, c);
+ break;
+ case '\"':
+ case '\'':
+ case '(':
+ case '{':
+ case '[':
+ case '}':
+ case ']':
+ case ')':
+ autoClose(d, c);
+ break;
+ case '\t':
+ boolean jumped = false;
+ if (isSmartTab()) {
+ jumped = smartIndentJump(d, c);
+ }
+ if (!jumped) {
+ c.text = getIndent();
+ }
+ break;
+ }
+ } else if (c.text.length() >= 1 && isSmartPaste())
+ smartPaste(d, c); // no smart backspace for paste
+ }
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCodeScanner.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCodeScanner.java?rev=1477113&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCodeScanner.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/ui/text/RutaCodeScanner.java Mon Apr 29 14:50:56 2013
@@ -0,0 +1,108 @@
+/*
+ * 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.
+*/
+
+package org.apache.uima.ruta.ide.ui.text;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.core.IRutaKeywords;
+import org.apache.uima.ruta.ide.core.RutaKeywordsManager;
+import org.eclipse.dltk.ui.text.AbstractScriptScanner;
+import org.eclipse.dltk.ui.text.IColorManager;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+
+
+public class RutaCodeScanner extends AbstractScriptScanner {
+
+ private static String fgTokenProperties[] = new String[] {
+ RutaColorConstants.TM_SINGLE_LINE_COMMENT, RutaColorConstants.TM_DEFAULT,
+ RutaColorConstants.TM_KEYWORD, RutaColorConstants.TM_KEYWORD_RETURN,
+ RutaColorConstants.TM_NUMBER, RutaColorConstants.TM_FUNCTION,
+ RutaColorConstants.TM_CONDITION, RutaColorConstants.TM_ACTION,
+ RutaColorConstants.TM_RULE, RutaColorConstants.TM_DECLARATION,
+ RutaColorConstants.TM_BASICSYMBOL, RutaColorConstants.TM_THEN };
+
+ public RutaCodeScanner(IColorManager manager, IPreferenceStore store) {
+ super(manager, store);
+ initialize();
+ }
+
+ @Override
+ protected String[] getTokenProperties() {
+ return fgTokenProperties;
+ }
+
+ @Override
+ protected List createRules() {
+ List<IRule> rules = new ArrayList<IRule>();
+ IToken keyword = getToken(RutaColorConstants.TM_KEYWORD);
+ IToken rule = getToken(RutaColorConstants.TM_RULE);
+ IToken comment = getToken(RutaColorConstants.TM_SINGLE_LINE_COMMENT);
+ IToken other = getToken(RutaColorConstants.TM_DEFAULT);
+ IToken declaration = getToken(RutaColorConstants.TM_DECLARATION);
+ IToken basicSymbol = getToken(RutaColorConstants.TM_BASICSYMBOL);
+ IToken function = getToken(RutaColorConstants.TM_FUNCTION);
+ IToken condition = getToken(RutaColorConstants.TM_CONDITION);
+ IToken action = getToken(RutaColorConstants.TM_ACTION);
+ IToken then = getToken(RutaColorConstants.TM_THEN);
+ IToken number = getToken(RutaColorConstants.TM_NUMBER);
+ IToken string = getToken(RutaColorConstants.TM_STRING);
+
+ // rules.add(new MultiLineRule("/*", "*/", comment, '\\', true));
+ // rules.add(new EndOfLineRule("//", comment));
+ rules.add(new WhitespaceRule(new RutaWhitespaceDetector()));
+ RutaWordRule wordRule = new RutaWordRule(new RutaWordDetector(), other, rule);
+
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.CONDITION)) {
+ wordRule.addWord(each, condition);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.DECLARATION)) {
+ wordRule.addWord(each, declaration);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.ACTION)) {
+ wordRule.addWord(each, action);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.BASIC)) {
+ wordRule.addWord(each, basicSymbol);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.BOOLEANFUNCTION)) {
+ wordRule.addWord(each, function);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.NUMBERFUNCTION)) {
+ wordRule.addWord(each, function);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.STRINGFUNCTION)) {
+ wordRule.addWord(each, function);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.TYPEFUNCTION)) {
+ wordRule.addWord(each, function);
+ }
+ for (String each : RutaKeywordsManager.getKeywords(IRutaKeywords.THEN)) {
+ wordRule.addWord(each, then);
+ }
+ rules.add(wordRule);
+
+ setDefaultReturnToken(other);
+ return rules;
+ }
+}