org.eclipse.wst.css.ui_1.0.601.v201201101544

16:48:57.740 INFO  jd.cli.Main - Decompiling org.eclipse.wst.css.ui_1.0.601.v201201101544.jar
package org.eclipse.wst.css.ui;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
import org.eclipse.wst.css.core.internal.format.FormatProcessorCSS;
import org.eclipse.wst.css.ui.internal.contentassist.CSSStructuredContentAssistProcessor;
import org.eclipse.wst.css.ui.internal.style.LineStyleProviderForCSS;
import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
import org.eclipse.wst.sse.ui.internal.format.StructuredFormattingStrategy;
import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;

public class StructuredTextViewerConfigurationCSS
  extends StructuredTextViewerConfiguration
{
  private String[] fConfiguredContentTypes;
  private LineStyleProvider fLineStyleProviderForCSS;
  
  public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType)
  {
    List allStrategies = new ArrayList(0);
    
    IAutoEditStrategy[] superStrategies = super.getAutoEditStrategies(sourceViewer, contentType);
    for (int i = 0; i < superStrategies.length; i++) {
      allStrategies.add(superStrategies[i]);
    }
    return (IAutoEditStrategy[])allStrategies.toArray(new IAutoEditStrategy[0]);
  }
  
  public String[] getConfiguredContentTypes(ISourceViewer sourceViewer)
  {
    if (fConfiguredContentTypes == null) {
      fConfiguredContentTypes = new String[] { "org.eclipse.wst.css.STYLE", "org.eclipse.wst.css.COMMENT", "org.eclipse.wst.sse.ST_DEFAULT", "org.eclipse.wst.sse.UNKNOWN_PARTITION_TYPE" };
    }
    return fConfiguredContentTypes;
  }
  
  protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType)
  {
    IContentAssistProcessor processor = new CSSStructuredContentAssistProcessor(
      getContentAssistant(), partitionType, sourceViewer);
    return new IContentAssistProcessor[] { processor };
  }
  
  public IContentFormatter getContentFormatter(ISourceViewer sourceViewer)
  {
    IContentFormatter formatter = super.getContentFormatter(sourceViewer);
    if (!(formatter instanceof MultiPassContentFormatter)) {
      formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), "org.eclipse.wst.css.STYLE");
    }
    ((MultiPassContentFormatter)formatter).setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorCSS()));
    
    return formatter;
  }
  
  public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType)
  {
    Vector vector = new Vector();
    
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    int indentationWidth = preferences.getInt("indentationSize");
    String indentCharPref = preferences.getString("indentationChar");
    boolean useSpaces = "space".equals(indentCharPref);
    for (int i = 0; i <= indentationWidth; i++)
    {
      StringBuffer prefix = new StringBuffer();
      boolean appendTab = false;
      if (useSpaces)
      {
        for (int j = 0; j + i < indentationWidth; j++) {
          prefix.append(' ');
        }
        if (i != 0) {
          appendTab = true;
        }
      }
      else
      {
        for (int j = 0; j < i; j++) {
          prefix.append(' ');
        }
        if (i != indentationWidth) {
          appendTab = true;
        }
      }
      if (appendTab)
      {
        prefix.append('\t');
        vector.add(prefix.toString());
        
        prefix.deleteCharAt(prefix.length() - 1);
      }
      vector.add(prefix.toString());
    }
    vector.add("");
    
    return (String[])vector.toArray(new String[vector.size()]);
  }
  
  public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType)
  {
    LineStyleProvider[] providers = (LineStyleProvider[])null;
    if ((partitionType == "org.eclipse.wst.css.STYLE") || (partitionType == "org.eclipse.wst.css.COMMENT")) {
      providers = new LineStyleProvider[] { getLineStyleProviderForCSS() };
    }
    return providers;
  }
  
  private LineStyleProvider getLineStyleProviderForCSS()
  {
    if (fLineStyleProviderForCSS == null) {
      fLineStyleProviderForCSS = new LineStyleProviderForCSS();
    }
    return fLineStyleProviderForCSS;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.css.ui.StructuredTextViewerConfigurationCSS
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.css.ui.internal;

import java.util.ResourceBundle;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
import org.eclipse.wst.sse.ui.internal.actions.ActionContributor;

public class ActionContributorCSS
  extends ActionContributor
{
  private static final String[] EDITOR_IDS = { "org.eclipse.wst.css.core.csssource.source", "org.eclipse.wst.sse.ui.StructuredTextEditor" };
  protected RetargetTextEditorAction fContentAssist = null;
  protected RetargetTextEditorAction fCleanupDocument = null;
  protected RetargetTextEditorAction fFormatDocument = null;
  protected RetargetTextEditorAction fFormatActiveElements = null;
  
  public ActionContributorCSS()
  {
    ResourceBundle resourceBundle = CSSUIMessages.getResourceBundle();
    
    fContentAssist = new RetargetTextEditorAction(resourceBundle, "");
    fContentAssist.setActionDefinitionId("org.eclipse.ui.edit.text.contentAssist.proposals");
    
    fCleanupDocument = new RetargetTextEditorAction(resourceBundle, "");
    fCleanupDocument.setActionDefinitionId("org.eclipse.wst.sse.ui.cleanup.document");
    
    fFormatDocument = new RetargetTextEditorAction(resourceBundle, "");
    fFormatDocument.setActionDefinitionId("org.eclipse.wst.sse.ui.format.document");
    
    fFormatActiveElements = new RetargetTextEditorAction(resourceBundle, "");
    fFormatActiveElements.setActionDefinitionId("org.eclipse.wst.sse.ui.format.active.elements");
  }
  
  protected String[] getExtensionIDs()
  {
    return EDITOR_IDS;
  }
  
  protected void addToMenu(IMenuManager menu)
  {
    IMenuManager editMenu = menu.findMenuUsingPath("edit");
    if (editMenu != null)
    {
      editMenu.add(fCommandsSeparator);
      editMenu.add(fToggleInsertModeAction);
      editMenu.add(fCommandsSeparator);
      editMenu.add(fExpandSelectionToMenu);
      editMenu.add(fCommandsSeparator);
      editMenu.add(fContentAssist);
      editMenu.add(fMenuAdditionsGroupMarker);
    }
    String sourceMenuLabel = CSSUIMessages.SourceMenu_label;
    String sourceMenuId = "sourceMenuId";
    IMenuManager sourceMenu = new MenuManager(sourceMenuLabel, sourceMenuId);
    menu.insertAfter("edit", sourceMenu);
    if (sourceMenu != null)
    {
      sourceMenu.add(fCommandsSeparator);
      sourceMenu.add(fShiftRight);
      sourceMenu.add(fShiftLeft);
      sourceMenu.add(fCleanupDocument);
      sourceMenu.add(fFormatDocument);
      sourceMenu.add(fFormatActiveElements);
      sourceMenu.add(fCommandsSeparator);
    }
    IMenuManager navigateMenu = menu.findMenuUsingPath("navigate");
    if (navigateMenu != null)
    {
      IMenuManager gotoGroup = navigateMenu.findMenuUsingPath("goTo");
      if (gotoGroup != null) {
        gotoGroup.add(fGotoMatchingBracketAction);
      }
    }
  }
  
  public void setActiveEditor(IEditorPart activeEditor)
  {
    super.setActiveEditor(activeEditor);
    
    ITextEditor textEditor = getTextEditor(activeEditor);
    
    fContentAssist.setAction(getAction(textEditor, "ContentAssistProposals"));
    
    fCleanupDocument.setAction(getAction(textEditor, "CleanupDocument"));
    fFormatDocument.setAction(getAction(textEditor, "FormatDocument"));
    fFormatActiveElements.setAction(getAction(textEditor, "FormatActiveElements"));
    fCleanupDocument.setEnabled((textEditor != null) && (textEditor.isEditable()));
    fFormatDocument.setEnabled((textEditor != null) && (textEditor.isEditable()));
    fFormatActiveElements.setEnabled((textEditor != null) && (textEditor.isEditable()));
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.css.ui.internal.ActionContributorCSS
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.css.ui.internal;

import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.osgi.util.NLS;

public class CSSUIMessages
  extends NLS
{
  private static final String BUNDLE_NAME = "org.eclipse.wst.css.ui.internal.CSSUIPluginResources";
  private static ResourceBundle fResourceBundle;
  public static String ID_Selector_Case__UI_;
  public static String INFO_Not_Categorized_1;
  public static String PrefsLabel_WrappingWithoutAttr;
  public static String PrefsLabel_WrappingInsertLineBreak;
  public static String PrefsLabel_CaseGroup;
  public static String PrefsLabel_CaseIdent;
  public static String PrefsLabel_CasePropName;
  public static String PrefsLabel_CasePropValue;
  public static String PrefsLabel_CaseIdentUpper;
  public static String PrefsLabel_CaseIdentLower;
  public static String PrefsLabel_SelectorTagName;
  public static String PrefsLabel_CasePropNameUpper;
  public static String PrefsLabel_CasePropNameLower;
  public static String PrefsLabel_CasePropValueUpper;
  public static String PrefsLabel_CasePropValueLower;
  public static String PrefsLabel_SelectorTagNameUpper;
  public static String PrefsLabel_SelectorTagNameLower;
  public static String PrefsLabel_ColorSample;
  public static String PrefsLabel_ColorNormal;
  public static String PrefsLabel_ColorAtmarkRule;
  public static String PrefsLabel_ColorSelector;
  public static String PrefsLabel_ColorCombinator;
  public static String PrefsLabel_ColorUniversal;
  public static String PrefsLabel_ColorId;
  public static String PrefsLabel_ColorPseudoClass;
  public static String PrefsLabel_ColorClass;
  public static String PrefsLabel_ColorMedia;
  public static String PrefsLabel_ColorComment;
  public static String PrefsLabel_ColorPropertyName;
  public static String PrefsLabel_ColorPropertyValue;
  public static String PrefsLabel_ColorUri;
  public static String PrefsLabel_ColorString;
  public static String PrefsLabel_ColorColon;
  public static String PrefsLabel_ColorSemiColon;
  public static String PrefsLabel_ColorCurlyBrace;
  public static String PrefsLabel_ColorError;
  public static String PrefsLabel_ColorAttrDelimiter;
  public static String PrefsLabel_ColorAttrName;
  public static String PrefsLabel_ColorAttrValue;
  public static String PrefsLabel_ColorAttrOperator;
  public static String SortAction_0;
  public static String _UI_WIZARD_NEW_TITLE;
  public static String _UI_WIZARD_NEW_HEADING;
  public static String _UI_WIZARD_NEW_DESCRIPTION;
  public static String _ERROR_FILENAME_MUST_END_CSS;
  public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT;
  public static String Title_InvalidValue;
  public static String Message_InvalidValue;
  public static String FormatMenu_label;
  public static String Class_Selector_Case__UI_;
  public static String CleanupDocument_label;
  public static String CleanupDocument_tooltip;
  public static String CleanupDocument_description;
  public static String UI_none;
  public static String Cleanup_UI_;
  public static String CSS_Cleanup_UI_;
  public static String ToggleComment_tooltip;
  public static String AddBlockComment_tooltip;
  public static String RemoveBlockComment_tooltip;
  public static String Identifier_case__UI_;
  public static String Property_name_case__UI_;
  public static String Property_value_case__UI_;
  public static String Selector_tag_name_case__UI_;
  public static String Quote_values_UI_;
  public static String Format_source_UI_;
  public static String As_is_UI_;
  public static String Lower_UI_;
  public static String Upper_UI_;
  public static String SourceMenu_label;
  public static String Formatting_UI_;
  public static String Line_width__UI_;
  public static String Indent_using_tabs_;
  public static String Indent_using_spaces;
  public static String Indentation_size;
  public static String Indentation_size_tip;
  public static String StructureSelectEnclosing_label;
  public static String StructureSelectEnclosing_tooltip;
  public static String StructureSelectEnclosing_description;
  public static String StructureSelectNext_label;
  public static String StructureSelectNext_tooltip;
  public static String StructureSelectNext_description;
  public static String StructureSelectPrevious_label;
  public static String StructureSelectPrevious_tooltip;
  public static String StructureSelectPrevious_description;
  public static String Creating_files_encoding;
  public static String ResourceGroup_nameExists;
  public static String NewCSSTemplatesWizardPage_0;
  public static String NewCSSTemplatesWizardPage_1;
  public static String NewCSSTemplatesWizardPage_2;
  public static String NewCSSTemplatesWizardPage_3;
  public static String NewCSSTemplatesWizardPage_4;
  public static String NewCSSTemplatesWizardPage_5;
  public static String NewCSSTemplatesWizardPage_6;
  public static String NewCSSTemplatesWizardPage_7;
  public static String CSSContentSettingsPropertyPage_0;
  public static String CSSContentSettingsPropertyPage_1;
  public static String SyntaxColoringPage_0;
  public static String SyntaxColoringPage_2;
  public static String SyntaxColoringPage_3;
  public static String SyntaxColoringPage_4;
  public static String SyntaxColoringPage_5;
  public static String SyntaxColoringPage_6;
  public static String _UI_STRUCTURED_TEXT_EDITOR_PREFS_LINK;
  
  static
  {
    NLS.initializeMessages("org.eclipse.wst.css.ui.internal.CSSUIPluginResources", CSSUIMessages.class);
  }
  
  public static ResourceBundle getResourceBundle()
  {
    try
    {
      if (fResourceBundle == null) {
        fResourceBundle = ResourceBundle.getBundle("org.eclipse.wst.css.ui.internal.CSSUIPluginResources");
      }
    }
    catch (MissingResourceException localMissingResourceException)
    {
      fResourceBundle = null;
    }
    return fResourceBundle;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.css.ui.internal.CSSUIMessages
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.css.ui.internal;

import java.io.IOException;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.text.templates.ContextTypeRegistry;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry;
import org.eclipse.ui.editors.text.templates.ContributionTemplateStore;
import org.eclipse.ui.plugin.AbstractUIPlugin;

public class CSSUIPlugin
  extends AbstractUIPlugin
{
  public static final String ID = "org.eclipse.wst.css.ui";
  private static CSSUIPlugin plugin;
  private TemplateStore fTemplateStore;
  private ContextTypeRegistry fContextTypeRegistry;
  
  public CSSUIPlugin()
  {
    plugin = this;
  }
  
  public static CSSUIPlugin getDefault()
  {
    return plugin;
  }
  
  public static IWorkspace getWorkspace()
  {
    return ResourcesPlugin.getWorkspace();
  }
  
  public TemplateStore getTemplateStore()
  {
    if (fTemplateStore == null)
    {
      fTemplateStore = new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), "org.eclipse.wst.sse.ui.custom_templates");
      try
      {
        fTemplateStore.load();
      }
      catch (IOException e)
      {
        Logger.logException(e);
      }
    }
    return fTemplateStore;
  }
  
  public ContextTypeRegistry getTemplateContextRegistry()
  {
    if (fContextTypeRegistry == null)
    {
      ContributionContextTypeRegistry registry = new ContributionContextTypeRegistry();
      registry.addContextType("css_all");
      registry.addContextType("css_new");
      
      fContextTypeRegistry = registry;
    }
    return fContextTypeRegistry;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.css.ui.internal.CSSUIPlugin
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.css.ui.internal;

import com.ibm.icu.util.StringTokenizer;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle;

public class Logger
{
  private static final String PLUGIN_ID = "org.eclipse.wst.css.ui";
  private static final String TRACEFILTER_LOCATION = "/debug/tracefilter";
  public static final int OK = 0;
  public static final int INFO = 1;
  public static final int WARNING = 2;
  public static final int ERROR = 4;
  public static final int OK_DEBUG = 200;
  public static final int INFO_DEBUG = 201;
  public static final int WARNING_DEBUG = 202;
  public static final int ERROR_DEBUG = 204;
  
  protected static void _log(int level, String message, Throwable exception)
  {
    if (((level == 200) || (level == 201) || (level == 202) || (level == 204)) && 
      (!isDebugging())) {
      return;
    }
    int severity = 0;
    switch (level)
    {
    case 1: 
    case 201: 
      severity = 1;
      break;
    case 2: 
    case 202: 
      severity = 2;
      break;
    case 4: 
    case 204: 
      severity = 4;
    }
    message = message != null ? message : "null";
    Status statusObj = new Status(severity, "org.eclipse.wst.css.ui", severity, message, exception);
    Bundle bundle = Platform.getBundle("org.eclipse.wst.css.ui");
    if (bundle != null) {
      Platform.getLog(bundle).log(statusObj);
    }
  }
  
  protected static void _trace(String category, String message, Throwable exception)
  {
    if (isTracing(category))
    {
      message = message != null ? message : "null";
      Status statusObj = new Status(0, "org.eclipse.wst.css.ui", 0, message, exception);
      Bundle bundle = Platform.getBundle("org.eclipse.wst.css.ui");
      if (bundle != null) {
        Platform.getLog(bundle).log(statusObj);
      }
    }
  }
  
  public static boolean isDebugging()
  {
    return Platform.inDebugMode();
  }
  
  public static boolean isTracing(String category)
  {
    if (!isDebugging()) {
      return false;
    }
    String traceFilter = Platform.getDebugOption("org.eclipse.wst.css.ui/debug/tracefilter");
    if (traceFilter != null)
    {
      StringTokenizer tokenizer = new StringTokenizer(traceFilter, ",");
      while (tokenizer.hasMoreTokens())
      {
        String cat = tokenizer.nextToken().trim();
        if (category.equals(cat)) {
          return true;
        }
      }
    }
    return false;
  }
  
  public static void log(int level, String message)
  {
    _log(level, message, null);
  }
  
  public static void log(int level, String message, Throwable exception)
  {
    _log(level, message, exception);
  }
  
  public static void logException(String message, Throwable exception)
  {
    _log(4, message, exception);
  }
  
  public static void logException(Throwable exception)
  {
    _log(4, exception.getMessage(), exception);
  }
  
  public static void traceException(String category, String message, Throwable exception)
  {
    _trace(category, message, exception);
  }
  
  public static void traceException(String category, Throwable exception)
  {
    _trace(category, exception.getMessage(), exception);
  }
  
  public static void trace(String category, String message)
  {
    _trace(category, message, null);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.css.ui.internal.Logger
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.css.ui.internal.autoedit;

import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

class StructuredAutoEditStrategyCSS$CompoundRegion
{
  private IStructuredDocumentRegion documentRegion;
  private ITextRegion textRegion;
  final StructuredAutoEditStrategyCSS this$0;
  
  StructuredAutoEditStrategyCSS$CompoundRegion(StructuredAutoEditStrategyCSS paramStructuredAutoEditStrategyCSS, IStructuredDocumentRegion documentRegion, ITextRegion textRegion)
  {
    this$0 = paramStructuredAutoEditStrategyCSS;
    this.documentRegion = documentRegion;
    this.textRegion = textRegion;
  }
  
  IStructuredDocumentRegion getDocumentRegion()
  {
    return documentRegion;
  }
  
  ITextRegion getTextRegion()
  {
    return textRegion;
  }
  
  int getStart()
  {
    return textRegion != null ? textRegion.getStart() : documentRegion.getStart();
  }
  
  int getEnd()
  {
    return textRegion != null ? textRegion.getEnd() : documentRegion.getEnd();
  }
  
  String getType()
  {
    return textRegion != null ? textRegion.getType() : "UNKNOWN";
  }
  
  String getText()
  {
    return textRegion != null ? documentRegion.getText(textRegion) : "";
  }
  
  int getStartOffset()
  {
    return textRegion != null ? documentRegion.getStartOffset(textRegion) : documentRegion.getStartOffset();
  }
  
  int getEndOffset()
  {
    return textRegion != null ? documentRegion.getEndOffset(textRegion) : documentRegion.getEndOffset();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.wst.css.ui.internal.autoedit.StructuredAutoEditStrategyCSS.CompoundRegion
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.wst.css.ui.internal.autoedit;

import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.TextUtilities;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorExtension3;
import org.eclipse.wst.css.core.internal.CSSCorePlugin;
import org.eclipse.wst.css.core.internal.util.RegionIterator;
import org.eclipse.wst.css.ui.internal.Logger;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

public class StructuredAutoEditStrategyCSS
  implements IAutoEditStrategy
{
  protected IStructuredDocument structuredDocument = null;
  
  class CompoundRegion
  {
    private IStructuredDocumentRegion documentRegion;
    private ITextRegion textRegion;
    
    CompoundRegion(IStructuredDocumentRegion documentRegion, ITextRegion textRegion)
    {
      this.documentRegion = documentRegion;
      this.textRegion = textRegion;
    }
    
    IStructuredDocumentRegion getDocumentRegion()
    {
      return documentRegion;
    }
    
    ITextRegion getTextRegion()
    {
      return textRegion;
    }
    
    int getStart()
    {
      return textRegion != null ? textRegion.getStart() : documentRegion.getStart();
    }
    
    int getEnd()
    {
      return textRegion != null ? textRegion.getEnd() : documentRegion.getEnd();
    }
    
    String getType()
    {
      return textRegion != null ? textRegion.getType() : "UNKNOWN";
    }
    
    String getText()
    {
      return textRegion != null ? documentRegion.getText(textRegion) : "";
    }
    
    int getStartOffset()
    {
      return textRegion != null ? documentRegion.getStartOffset(textRegion) : documentRegion.getStartOffset();
    }
    
    int getEndOffset()
    {
      return textRegion != null ? documentRegion.getEndOffset(textRegion) : documentRegion.getEndOffset();
    }
  }
  
  protected void autoIndentAfterClose(DocumentCommand command, String regionType)
  {
    if (!setRangeForClose(command)) {
      return;
    }
    int position = offset + length;
    if ((position == -1) || (structuredDocument.getLength() == 0)) {
      return;
    }
    CompoundRegion region = prevCorrespondence(position, regionType);
    
    String str = getIndentFor(region, false);
    if (str != null) {
      text = (str + text);
    }
  }
  
  protected void autoIndentAfterNewLine(DocumentCommand command)
  {
    setRangeForNewLine(command);
    
    int position = offset;
    if ((position == -1) || (structuredDocument.getLength() == 0)) {
      return;
    }
    IStructuredDocumentRegion prev = getPreviousRegion(position);
    if ((prev == null) || (!"LBRACE".equals(prev.getType()))) {
      return;
    }
    IStructuredDocumentRegion next = prev.getNext();
    
    StringBuffer buf = new StringBuffer(text);
    try
    {
      IRegion line = structuredDocument.getLineInformationOfOffset(position);
      int contentStart = findEndOfWhiteSpace(structuredDocument, position, line.getOffset() + line.getLength());
      length = Math.max(contentStart - position, 0);
      buf.append(getIndentString());
      if ((next != null) && ("RBRACE".equals(next.getType())) && (!isOneLine(prev)))
      {
        shiftsCaret = false;
        caretOffset = (contentStart + buf.length());
        buf.append(TextUtilities.getDefaultLineDelimiter(structuredDocument));
      }
      text = buf.toString();
    }
    catch (BadLocationException localBadLocationException) {}
  }
  
  private boolean isOneLine(IStructuredDocumentRegion prev)
  {
    return endsWith(structuredDocument.getLegalLineDelimiters(), prev.getFullText()) != -1;
  }
  
  private IStructuredDocumentRegion getPreviousRegion(int offset)
  {
    IStructuredDocumentRegion prev = null;
    if (offset > 0) {
      prev = structuredDocument.getRegionAtCharacterOffset(offset - 1);
    }
    return prev;
  }
  
  public void customizeDocumentCommand(IDocument document, DocumentCommand command)
  {
    Object textEditor = getActiveTextEditor();
    if ((!(textEditor instanceof ITextEditorExtension3)) || (((ITextEditorExtension3)textEditor).getInsertMode() != ITextEditorExtension3.SMART_INSERT)) {
      return;
    }
    structuredDocument = ((IStructuredDocument)document);
    if ((length == 0) && (text != null)) {
      if (endsWith(document.getLegalLineDelimiters(), text) != -1) {
        autoIndentAfterNewLine(command);
      } else if (text.equals("}")) {
        autoIndentAfterClose(command, "RBRACE");
      } else if (text.equals("]")) {
        autoIndentAfterClose(command, "SELECTOR_ATTRIBUTE_END");
      } else if (text.equals(")")) {
        autoIndentAfterClose(command, "DECLARATION_VALUE_PARENTHESIS_CLOSE");
      }
    }
    if ((text != null) && (text.length() > 0) && (text.charAt(0) == '\t')) {
      smartInsertForTab(command, document);
    }
  }
  
  protected String getIndentFor(CompoundRegion region, boolean indentForNextRegion)
  {
    if (region == null) {
      return null;
    }
    IStructuredDocumentRegion flatNode = region.getDocumentRegion();
    if (flatNode == null) {
      return null;
    }
    try
    {
      if ((region.getType() == "LBRACE") || (region.getType() == "DELIMITER") || (region.getType() == "DECLARATION_DELIMITER"))
      {
        RegionIterator it = new RegionIterator(flatNode, region.getTextRegion());
        it.prev();
        while (it.hasPrev())
        {
          ITextRegion r = it.prev();
          region = new CompoundRegion(it.getStructuredDocumentRegion(), r);
          if (region.getType() != "S") {
            break;
          }
        }
        flatNode = region.getDocumentRegion();
        
        int position = flatNode.getStart();
        int line = structuredDocument.getLineOfOffset(position);
        int start = structuredDocument.getLineOffset(line);
        int end = findEndOfWhiteSpace(structuredDocument, start, position);
        return structuredDocument.get(start, end - start);
      }
      if ((region.getType() == "SELECTOR_ATTRIBUTE_START") || 
      
        (region.getType() == "DECLARATION_VALUE_FUNCTION") || (region.getType() == "DECLARATION_SEPARATOR"))
      {
        int position = flatNode.getStart() + region.getStart();
        int line = structuredDocument.getLineOfOffset(position);
        int start = structuredDocument.getLineOffset(line);
        int end = findEndOfWhiteSpace(structuredDocument, start, position);
        StringBuffer buf = new StringBuffer(structuredDocument.get(start, end - start));
        position += region.getText().length();
        if (indentForNextRegion)
        {
          int tokenStart = findEndOfWhiteSpace(structuredDocument, position, structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1);
          if (tokenStart < structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1) {
            position = tokenStart;
          }
        }
        while (position - end > 0)
        {
          buf.append(" ");
          end++;
        }
        return buf.toString();
      }
      return "";
    }
    catch (BadLocationException excp)
    {
      Logger.logException(excp);
    }
    return null;
  }
  
  protected CompoundRegion getPrevKeyRegion(int position, CompoundRegion currentRegion)
  {
    if ((currentRegion == null) && 
      (structuredDocument.getLastStructuredDocumentRegion() == null)) {
      return null;
    }
    if ((currentRegion != null) && ((currentRegion.getType() == "RBRACE") || (currentRegion.getType() == "SELECTOR_ATTRIBUTE_END") || (currentRegion.getType() == "DECLARATION_VALUE_PARENTHESIS_CLOSE"))) {
      return prevCorrespondence(currentRegion);
    }
    RegionIterator it = new RegionIterator(structuredDocument, position - 1);
    while (it.hasPrev())
    {
      ITextRegion r = it.prev();
      CompoundRegion region = new CompoundRegion(it.getStructuredDocumentRegion(), r);
      if ((region.getType() == "LBRACE") || 
      
        (region.getType() == "SELECTOR_ATTRIBUTE_START") || 
        
        (region.getType() == "DELIMITER") || (region.getType() == "DECLARATION_DELIMITER") || 
        
        (region.getType() == "DECLARATION_VALUE_FUNCTION")) {
        return region;
      }
      if ((region.getType() == "RBRACE") || (region.getType() == "SELECTOR_ATTRIBUTE_END") || (region.getType() == "DECLARATION_VALUE_PARENTHESIS_CLOSE"))
      {
        CompoundRegion pc = prevCorrespondence(region);
        if (pc == null) {
          break;
        }
        it.reset(pc.getDocumentRegion(), pc.getTextRegion());
        it.prev();
      }
      else if (region.getType() == "STRING")
      {
        RegionIterator itTmp = new RegionIterator(structuredDocument, position);
        if (region == itTmp.prev()) {
          return region;
        }
      }
      else if (region.getType() == "COMMENT")
      {
        RegionIterator itTmp = new RegionIterator(structuredDocument, position);
        if (region == itTmp.prev()) {
          return region;
        }
      }
      else if (region.getType() == "UNKNOWN")
      {
        String str = region.getText();
        if (str.charAt(str.length() - 1) == '\\') {
          return region;
        }
      }
      else if (region.getType() == "DECLARATION_SEPARATOR")
      {
        RegionIterator itPrev = new RegionIterator(region.getDocumentRegion(), region.getTextRegion());
        while (itPrev.hasPrev())
        {
          ITextRegion regionPrev = itPrev.prev();
          if (regionPrev.getType() == "RBRACE") {
            break;
          }
          if ((regionPrev.getType() == "DELIMITER") || (regionPrev.getType() == "DECLARATION_DELIMITER")) {
            return region;
          }
          if (regionPrev.getType() == "LBRACE")
          {
            while (itPrev.hasPrev())
            {
              regionPrev = itPrev.prev();
              if (regionPrev.getType() == "MEDIA") {
                break;
              }
              if ((regionPrev.getType() == "LBRACE") || (regionPrev.getType() == "RBRACE") || (regionPrev.getType() == "DELIMITER") || (regionPrev.getType() == "DECLARATION_DELIMITER")) {
                return region;
              }
            }
            if (regionPrev.getType() == "MEDIA") {
              break;
            }
            return region;
          }
        }
      }
    }
    return null;
  }
  
  protected CompoundRegion getRegion(int position)
  {
    IStructuredDocumentRegion flatNode = structuredDocument.getRegionAtCharacterOffset(position);
    if (flatNode != null) {
      return new CompoundRegion(flatNode, flatNode.getRegionAtCharacterOffset(position));
    }
    return null;
  }
  
  protected int needShift(CompoundRegion region, int position)
  {
    int shift = 0;
    if ((region == null) || (region.getType() == "DELIMITER") || (region.getType() == "DECLARATION_DELIMITER") || (region.getType() == "LBRACE"))
    {
      CompoundRegion cr = getRegion(position - 1);
      RegionIterator it = new RegionIterator(cr.getDocumentRegion(), cr.getTextRegion());
      ITextRegion nearestRegion = null;
      while (it.hasPrev())
      {
        nearestRegion = it.prev();
        if ((nearestRegion.getType() != "S") && (nearestRegion.getType() != "COMMENT")) {
          break;
        }
      }
      if ((nearestRegion != null) && ((nearestRegion.getType() == "LBRACE") || (nearestRegion.getType() == "RBRACE") || (nearestRegion.getType() == "DELIMITER") || (nearestRegion.getType() == "DECLARATION_DELIMITER"))) {
        shift--;
      } else if (region == null) {
        shift--;
      }
      shift++;
    }
    if ((region != null) && (region.getType() == "LBRACE"))
    {
      RegionIterator it = new RegionIterator(structuredDocument, position);
      if ((!it.hasPrev()) || (it.prev().getType() != "RBRACE")) {
        shift++;
      } else {
        shift = 0;
      }
    }
    return shift;
  }
  
  protected CompoundRegion prevCorrespondence(int position, String regionType)
  {
    RegionIterator it = new RegionIterator(structuredDocument, position - 1);
    ITextRegion region = null;
    int nest = 1;
    if (regionType == "RBRACE")
    {
      while (it.hasPrev())
      {
        region = it.prev();
        if (region.getType() == "LBRACE") {
          nest--;
        } else if (region.getType() == "RBRACE") {
          nest++;
        }
        if (nest <= 0) {
          break;
        }
      }
      if (nest == 0) {
        return new CompoundRegion(it.getStructuredDocumentRegion(), region);
      }
    }
    if (regionType == "SELECTOR_ATTRIBUTE_END")
    {
      while (it.hasPrev())
      {
        region = it.prev();
        if (region.getType() == "SELECTOR_ATTRIBUTE_START") {
          nest--;
        } else if (region.getType() == "SELECTOR_ATTRIBUTE_END") {
          nest++;
        }
        if (nest <= 0) {
          break;
        }
      }
      if (nest == 0) {
        return new CompoundRegion(it.getStructuredDocumentRegion(), region);
      }
    }
    if (regionType == "DECLARATION_VALUE_PARENTHESIS_CLOSE")
    {
      while (it.hasPrev())
      {
        region = it.prev();
        if (region.getType() == "DECLARATION_VALUE_FUNCTION") {
          nest--;
        } else if (region.getType() == "DECLARATION_VALUE_PARENTHESIS_CLOSE") {
          nest++;
        }
        if (nest <= 0) {
          break;
        }
      }
      if (nest == 0) {
        return new CompoundRegion(it.getStructuredDocumentRegion(), region);
      }
    }
    return null;
  }
  
  protected CompoundRegion prevCorrespondence(CompoundRegion region)
  {
    if (region == null) {
      return null;
    }
    IStructuredDocumentRegion flatNode = region.getDocumentRegion();
    int position = flatNode.getStart() + region.getStart();
    return prevCorrespondence(position, region.getType());
  }
  
  protected boolean setRangeForClose(DocumentCommand command)
  {
    int position = offset;
    if ((position == -1) || (structuredDocument.getLength() == 0)) {
      return false;
    }
    try
    {
      int p = position == structuredDocument.getLength() ? position - 1 : position;
      
      int line = structuredDocument.getLineOfOffset(p);
      int start = structuredDocument.getLineOffset(line);
      RegionIterator it = new RegionIterator(structuredDocument, start);
      boolean allWhiteSpace = false;
      while (it.hasNext())
      {
        ITextRegion region = it.next();
        if (region.getType() != "S") {
          break;
        }
        if (it.getStructuredDocumentRegion().getEndOffset(region) > p)
        {
          allWhiteSpace = true;
          break;
        }
      }
      if (allWhiteSpace)
      {
        length -= start - offset;
        offset = start;
        return true;
      }
    }
    catch (BadLocationException excp)
    {
      Logger.logException(excp);
    }
    return false;
  }
  
  protected void setRangeForNewLine(DocumentCommand command)
  {
    int position = offset;
    if ((position == -1) || (structuredDocument.getLength() == 0)) {
      return;
    }
    try
    {
      if (position > 0)
      {
        IStructuredDocumentRegion flatNode = structuredDocument.getRegionAtCharacterOffset(position - 1);
        if (flatNode != null)
        {
          ITextRegion region = flatNode.getRegionAtCharacterOffset(position - 1);
          if (region.getType() == "S")
          {
            int end = offset + length;
            int nLine = structuredDocument.getLineOfOffset(position);
            int nStartPos = structuredDocument.getLineOffset(nLine);
            if (nStartPos < flatNode.getStartOffset(region)) {
              nStartPos = flatNode.getStartOffset(region);
            }
            offset = nStartPos;
            length = (end - offset);
          }
        }
      }
      if (position < structuredDocument.getLength())
      {
        IStructuredDocumentRegion flatNode = structuredDocument.getRegionAtCharacterOffset(position);
        if (flatNode != null)
        {
          ITextRegion region = flatNode.getRegionAtCharacterOffset(position);
          if (region.getType() == "S")
          {
            int nLine = structuredDocument.getLineOfOffset(position);
            String currentLineDelim = structuredDocument.getLineDelimiter(nLine);
            int nEndPos = structuredDocument.getLineOffset(nLine) + structuredDocument.getLineLength(nLine) - (currentLineDelim != null ? currentLineDelim.length() : 0);
            if (nEndPos > flatNode.getEndOffset(region)) {
              nEndPos = flatNode.getEndOffset(region);
            }
            length = (nEndPos - offset);
          }
        }
      }
    }
    catch (BadLocationException localBadLocationException) {}
  }
  
  private static int endsWith(String[] searchStrings, String text)
  {
    for (int i = 0; i < searchStrings.length; i++) {
      if (text.endsWith(searchStrings[i])) {
        return i;
      }
    }
    return -1;
  }
  
  private static int findEndOfWhiteSpace(IDocument document, int offset, int end)
    throws BadLocationException
  {
    while (offset < end)
    {
      char c = document.getChar(offset);
      if ((c != ' ') && (c != '\t')) {
        return offset;
      }
      offset++;
    }
    return end;
  }
  
  private String getIndentString()
  {
    StringBuffer indent = new StringBuffer();
    
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    if (preferences != null)
    {
      char indentChar = ' ';
      String indentCharPref = preferences.getString("indentationChar");
      if ("tab".equals(indentCharPref)) {
        indentChar = '\t';
      }
      int indenta
1 2 3 4 5 6 7 8 9 10 11 12 13

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd