DLTK Adding Todo Task Tag Support

From Eclipsepedia

Jump to: navigation, search

Summary

This mini tutorial outlines the steps required to add todo task tag support to your plugin.

Prerequisites

This tutorial assumes the following have been implemented:

  • document partitioning
  • syntax highlighting

Steps

  • If you have not done so already, set up a preference initializer for your core plugin.
  • Once complete, initialize your plugin store's default values with a call to:
package org.eclipse.dltk.python.internal.core;
 
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.dltk.compiler.task.TaskTagUtils;
import org.eclipse.dltk.python.core.PythonPlugin;
 
 
public class PythonCorePreferenceInitializer extends AbstractPreferenceInitializer {
 
    public void initializeDefaultPreferences() {
       Preferences store = PythonPlugin.getDefault().getPluginPreferences();
       TaskTagUtils.initializeDefaultValues(store);
    }
}
  • Add org.eclipse.dltk.validators.core as a dependency for your core plugin.
  • Create an implementation of org.eclipse.dltk.validators.core.AbstractTodoParserBuildParticipantType
package org.eclipse.dltk.python.internal.core.parser;
 
import org.eclipse.dltk.compiler.task.ITodoTaskPreferences;
import org.eclipse.dltk.compiler.task.TodoTaskPreferencesOnPrefernceLookupDelegate;
import org.eclipse.dltk.core.IScriptProject;
import org.eclipse.dltk.core.builder.AbstractTodoTaskBuildParticipantType;
import org.eclipse.dltk.python.core.PythonPlugin;
 
public class PythonTodoParserType extends AbstractTodoTaskBuildParticipantType {
 
    protected ITodoTaskPreferences getPreferences(IScriptProject project) {
	return new TodoTaskPreferencesOnPreferenceLookupDelegate(PythonPlugin.PLUGIN_ID, project);
    }
}
  • and add the extension definition, this also includes adding a parser build participant if you have not already done so.
<extension
  point="org.eclipse.dltk.core.buildParticipant">
  <buildParticipant
    class="org.eclipse.dltk.core.builder.ParserBuildParticipantFactory"
    id="org.eclipse.dltk.python.buildParticipant.parser"
    name="%parserBuildParticipant.name"
    nature="org.eclipse.dltk.python.core.nature">
  </buildParticipant>
  <buildParticipant
    class="org.eclipse.dltk.python.internal.core.parser.PythonTodoParserType"
    id="org.eclipse.dltk.python.todo"
    name="%taskTagsBuildParticipant.name"
    nature="org.eclipse.dltk.python.core.nature">
    <requires
      id="org.eclipse.dltk.python.buildParticipant.parser">
    </requires>
  </buildParticipant>
</extension>
  • replace the comment scanner in your org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration implementation with a org.eclipse.dltk.ui.text.ScriptCommentScanner, ie:
fCommentScanner = createCommentScanner(PythonColorConstants.PYTHON_SINGLE_LINE_COMMENT, PythonColorConstants.PYTHON_TODO_TAG);
  • add ui preference constants and their initialization values, ie:
public final static String COMMENT_TASK_TAGS = PythonColorConstants.PYTHON_TODO_TAG;
public final static String COMMENT_TASK_TAGS_BOLD = COMMENT_TASK_TAGS + EDITOR_BOLD_SUFFIX;
 
PreferenceConverter.setDefault(store, COMMENT_TASK_TAGS, new RGB(127, 159, 191));
store.setDefault(COMMENT_TASK_TAGS_BOLD, true);
  • Create an implementation of org.eclipse.dltk.ui.preferences.AbstractConfigurationBlockPropertyAndPreferencePage
package org.eclipse.dltk.python.internal.ui.preferences;
 
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.dltk.python.core.PythonPlugin;
import org.eclipse.dltk.python.core.PythonNature;
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 PythonTodoTaskPreferencePage extends AbstractConfigurationBlockPropertyAndPreferencePage {
 
    static final PreferenceKey CASE_SENSITIVE = AbstractTodoTaskOptionsBlock.createCaseSensitiveKey(PythonPlugin.PLUGIN_ID);
 
    static final PreferenceKey ENABLED = AbstractTodoTaskOptionsBlock.createEnabledKey(PythonPlugin.PLUGIN_ID);
 
    static final PreferenceKey TAGS = AbstractTodoTaskOptionsBlock.createTagKey(PythonPlugin.PLUGIN_ID);
 
    protected String getHelpId() {
        return null;
    }
 
    protected void setDescription() {
	setDescription(PythonPreferencesMessages.TodoTaskDescription);
    }
 
    protected Preferences getPluginPreferences() {
	return PythonPlugin.getDefault().getPluginPreferences();
    }
 
    protected AbstractOptionsBlock createOptionsBlock(IStatusChangeListener newStatusChangedListener, IProject project,
            IWorkbenchPreferenceContainer container) {
	return new AbstractTodoTaskOptionsBlock(newStatusChangedListener,project, getPreferenceKeys(), container) {
		protected PreferenceKey getTags() {
			return TAGS;
		}
 
		protected PreferenceKey getEnabledKey() {
		    return ENABLED;
		}
 
		protected PreferenceKey getCaseSensitiveKey() {
	  	    return CASE_SENSITIVE;
		}
	};
    }
 
    protected String getNatureId() {
        return PythonNature.NATURE_ID;
    }
 
    protected String getProjectHelpId() {
	return null;
    }
 
    protected void setPreferenceStore() {
	setPreferenceStore(new PreferencesAdapter(PythonPlugin.getDefault().getPluginPreferences()));
    }
 
    protected String getPreferencePageId() {
	return "org.eclipse.dltk.python.preferences.todo";
    }
 
    protected String getPropertyPageId() {
	return "org.eclipse.dltk.python.propertyPage.todo";
    }
 
    protected PreferenceKey[] getPreferenceKeys() {
	return new PreferenceKey[] { TAGS, ENABLED, CASE_SENSITIVE };
    }
}
  • add the preference page definition
<page
  category="org.eclipse.dltk.python.preferences"
  class="org.eclipse.dltk.python.internal.ui.preferences.PythonTodoTaskPreferencePage"
  id="org.eclipse.dltk.python.ui.editor.TodoTasks"
  name="%PythonTaskTags.name"/>
  • and the property page definition
<page
  category="org.eclipse.dltk.python.propertyPage"
  class="org.eclipse.dltk.python.internal.ui.preferences.PythonTodoTaskPreferencePage"
  id="org.eclipse.dltk.python.propertyPage.todo"
  name="%PythonTodoPropertyPage.name">
  <enabledWhen>
    <adapt type="org.eclipse.core.resources.IProject">
      <test property="org.eclipse.core.resources.projectNature" value="org.eclipse.dltk.python.core.nature"/>
    </adapt>         
  </enabledWhen>
</page>
  • add an entry for the color syntax to your org.eclipse.dltk.ui.preferences.AbstractScriptEditorColoringConfigurationBlock implementation, ie:
{ 
  PreferencesMessages.DLTKEditorPreferencePage_CommentTaskTags,
  PythonPreferenceConstants.COMMENT_TASK_TAGS, 
  sCommentsCategory 
}
  • and you're done! if all went right, you should have task tag support.