org.eclipse.ui.editors_3.8.0.v20120523-1540

16:48:07.708 INFO  jd.cli.Main - Decompiling org.eclipse.ui.editors_3.8.0.v20120523-1540.jar
package org.eclipse.ui.editors.text;

import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.texteditor.StatusTextEditor;

class DefaultEncodingSupport$1
  implements IEclipsePreferences.IPreferenceChangeListener
{
  final DefaultEncodingSupport this$0;
  
  DefaultEncodingSupport$1(DefaultEncodingSupport paramDefaultEncodingSupport)
  {
    this$0 = paramDefaultEncodingSupport;
  }
  
  public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event)
  {
    if ("encoding".equals(event.getKey()))
    {
      Runnable runnable = new DefaultEncodingSupport.2(this);
      if (Display.getCurrent() != null)
      {
        runnable.run();
      }
      else
      {
        Shell shell;
        Shell shell;
        if (DefaultEncodingSupport.access$0(this$0) != null) {
          shell = DefaultEncodingSupport.access$0(this$0).getSite().getShell();
        } else {
          shell = DefaultEncodingSupport.access$1();
        }
        Display display;
        Display display;
        if (shell != null) {
          display = shell.getDisplay();
        } else {
          display = Display.getDefault();
        }
        display.asyncExec(runnable);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DefaultEncodingSupport.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

class DefaultEncodingSupport$2
  implements Runnable
{
  final DefaultEncodingSupport.1 this$1;
  
  DefaultEncodingSupport$2(DefaultEncodingSupport.1 param1)
  {
    this$1 = param1;
  }
  
  public void run()
  {
    DefaultEncodingSupport.1.access$0(this$1).setEncoding(null, false);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DefaultEncodingSupport.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.ui.texteditor.StatusTextEditor;

class DefaultEncodingSupport$3
  implements Runnable
{
  final DefaultEncodingSupport this$0;
  
  DefaultEncodingSupport$3(DefaultEncodingSupport paramDefaultEncodingSupport)
  {
    this$0 = paramDefaultEncodingSupport;
  }
  
  public void run()
  {
    DefaultEncodingSupport.access$0(this$0).doRevertToSaved();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DefaultEncodingSupport.3
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.jface.action.IAction;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

class DefaultEncodingSupport$4
  extends SelectionAdapter
{
  final DefaultEncodingSupport this$0;
  private final IAction val$action;
  
  DefaultEncodingSupport$4(DefaultEncodingSupport paramDefaultEncodingSupport, IAction paramIAction)
  {
    this$0 = paramDefaultEncodingSupport;val$action = paramIAction;
  }
  
  public void widgetSelected(SelectionEvent e)
  {
    val$action.run();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DefaultEncodingSupport.4
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import java.io.CharConversionException;
import java.io.UnsupportedEncodingException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.editors.text.NLSUtility;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.StatusTextEditor;
import org.eclipse.ui.texteditor.TextEditorAction;

public class DefaultEncodingSupport
  implements IEncodingSupport
{
  private IEclipsePreferences.IPreferenceChangeListener fPreferenceChangeListener;
  private StatusTextEditor fTextEditor;
  
  public void initialize(StatusTextEditor textEditor)
  {
    fTextEditor = textEditor;
    
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.core.resources");
    
    fPreferenceChangeListener = new IEclipsePreferences.IPreferenceChangeListener()
    {
      public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event)
      {
        if ("encoding".equals(event.getKey()))
        {
          Runnable runnable = new DefaultEncodingSupport.2(this);
          if (Display.getCurrent() != null)
          {
            runnable.run();
          }
          else
          {
            Shell shell;
            Shell shell;
            if (fTextEditor != null) {
              shell = fTextEditor.getSite().getShell();
            } else {
              shell = DefaultEncodingSupport.access$1();
            }
            Display display;
            Display display;
            if (shell != null) {
              display = shell.getDisplay();
            } else {
              display = Display.getDefault();
            }
            display.asyncExec(runnable);
          }
        }
      }
    };
    prefs.addPreferenceChangeListener(fPreferenceChangeListener);
  }
  
  public void dispose()
  {
    IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode("org.eclipse.core.resources");
    prefs.removePreferenceChangeListener(fPreferenceChangeListener);
    fTextEditor = null;
  }
  
  public void reset() {}
  
  protected void setEncoding(String encoding, boolean overwrite)
  {
    IDocumentProvider p = fTextEditor.getDocumentProvider();
    if ((p instanceof IStorageDocumentProvider))
    {
      IEditorInput input = fTextEditor.getEditorInput();
      IStorageDocumentProvider provider = (IStorageDocumentProvider)p;
      String current = provider.getEncoding(input);
      if (!fTextEditor.isDirty())
      {
        String internal = encoding == null ? "" : encoding;
        boolean apply = ((overwrite) || (current == null)) && (!internal.equals(current));
        if (apply)
        {
          provider.setEncoding(input, encoding);
          Runnable encodingSetter = 
            new Runnable()
            {
              public void run()
              {
                fTextEditor.doRevertToSaved();
              }
            };
            Display display = fTextEditor.getSite().getShell().getDisplay();
            if ((display != null) && (!display.isDisposed())) {
              BusyIndicator.showWhile(display, encodingSetter);
            } else {
              encodingSetter.run();
            }
          }
        }
      }
    }
    
    public void setEncoding(String encoding)
    {
      setEncoding(encoding, true);
    }
    
    public String getEncoding()
    {
      IDocumentProvider p = fTextEditor.getDocumentProvider();
      if ((p instanceof IStorageDocumentProvider))
      {
        IStorageDocumentProvider provider = (IStorageDocumentProvider)p;
        return provider.getEncoding(fTextEditor.getEditorInput());
      }
      return null;
    }
    
    public String getDefaultEncoding()
    {
      IDocumentProvider p = fTextEditor.getDocumentProvider();
      if ((p instanceof IStorageDocumentProvider))
      {
        IStorageDocumentProvider provider = (IStorageDocumentProvider)p;
        return provider.getDefaultEncoding();
      }
      return null;
    }
    
    public String getStatusHeader(IStatus status)
    {
      Throwable t = status.getException();
      if ((t instanceof CharConversionException)) {
        return TextEditorMessages.Editor_error_unreadable_encoding_header;
      }
      if ((t instanceof UnsupportedEncodingException)) {
        return TextEditorMessages.Editor_error_unsupported_encoding_header;
      }
      return null;
    }
    
    public String getStatusBanner(IStatus status)
    {
      Throwable t = status.getException();
      if ((t instanceof CharConversionException)) {
        return TextEditorMessages.Editor_error_unreadable_encoding_banner;
      }
      if ((t instanceof UnsupportedEncodingException)) {
        return TextEditorMessages.Editor_error_unsupported_encoding_banner;
      }
      return null;
    }
    
    public String getStatusMessage(IStatus status)
    {
      Throwable t = status.getException();
      if (((t instanceof CharConversionException)) || ((t instanceof UnsupportedEncodingException)))
      {
        String encoding = getEncoding();
        if (encoding == null) {
          encoding = getDefaultEncoding();
        }
        if ((t instanceof CharConversionException))
        {
          if (encoding != null) {
            return NLSUtility.format(TextEditorMessages.Editor_error_unreadable_encoding_message_arg, encoding);
          }
          return TextEditorMessages.Editor_error_unreadable_encoding_message;
        }
        if ((t instanceof UnsupportedEncodingException))
        {
          if (encoding != null) {
            return NLSUtility.format(TextEditorMessages.Editor_error_unsupported_encoding_message_arg, encoding);
          }
          return TextEditorMessages.Editor_error_unsupported_encoding_message;
        }
      }
      return null;
    }
    
    public boolean isEncodingError(IStatus status)
    {
      if ((status == null) || (status.getSeverity() != 4)) {
        return false;
      }
      Throwable t = status.getException();
      return ((t instanceof CharConversionException)) || ((t instanceof UnsupportedEncodingException));
    }
    
    public void createStatusEncodingChangeControl(Composite parent, IStatus status)
    {
      IAction action = fTextEditor.getAction("ChangeEncoding");
      if ((action instanceof TextEditorAction)) {
        ((TextEditorAction)action).update();
      }
      if ((action == null) || (!action.isEnabled())) {
        return;
      }
      Shell shell = parent.getShell();
      Display display = shell.getDisplay();
      Color bgColor = display.getSystemColor(25);
      
      Button button = new Button(parent, 8388616);
      button.setText(action.getText());
      button.addSelectionListener(new SelectionAdapter()
      {
        private final IAction val$action;
        
        public void widgetSelected(SelectionEvent e)
        {
          val$action.run();
        }
      });
      button.setFocus();
      
      Label filler = new Label(parent, 0);
      filler.setLayoutData(new GridData(1808));
      filler.setBackground(bgColor);
    }
    
    private static Shell getActiveWorkbenchShell()
    {
      IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      if (window != null) {
        return window.getShell();
      }
      return null;
    }
  }

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DefaultEncodingSupport
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;

class DocumentReader$DocumentCharSequence
  implements CharSequence
{
  private IDocument fDocument;
  
  public DocumentReader$DocumentCharSequence(IDocument document)
  {
    fDocument = document;
  }
  
  public int length()
  {
    return fDocument.getLength();
  }
  
  public char charAt(int index)
  {
    try
    {
      return fDocument.getChar(index);
    }
    catch (BadLocationException x)
    {
      throw new IndexOutOfBoundsException(x.getLocalizedMessage());
    }
  }
  
  public CharSequence subSequence(int start, int end)
  {
    try
    {
      return fDocument.get(start, end - start);
    }
    catch (BadLocationException x)
    {
      throw new IndexOutOfBoundsException(x.getLocalizedMessage());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DocumentReader.DocumentCharSequence
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;

class DocumentReader$InternalDocumentListener
  implements IDocumentListener
{
  final DocumentReader this$0;
  
  private DocumentReader$InternalDocumentListener(DocumentReader paramDocumentReader)
  {
    this$0 = paramDocumentReader;
  }
  
  DocumentReader$InternalDocumentListener(DocumentReader paramDocumentReader, InternalDocumentListener paramInternalDocumentListener)
  {
    this(paramDocumentReader);
  }
  
  public void documentAboutToBeChanged(DocumentEvent event)
  {
    DocumentReader.access$0(this$0);
  }
  
  public void documentChanged(DocumentEvent event) {}
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DocumentReader.InternalDocumentListener
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import java.io.IOException;
import java.io.Reader;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;

class DocumentReader
  extends Reader
{
  private volatile CharSequence fCharSequence;
  private int fLength;
  
  private static class DocumentCharSequence
    implements CharSequence
  {
    private IDocument fDocument;
    
    public DocumentCharSequence(IDocument document)
    {
      fDocument = document;
    }
    
    public int length()
    {
      return fDocument.getLength();
    }
    
    public char charAt(int index)
    {
      try
      {
        return fDocument.getChar(index);
      }
      catch (BadLocationException x)
      {
        throw new IndexOutOfBoundsException(x.getLocalizedMessage());
      }
    }
    
    public CharSequence subSequence(int start, int end)
    {
      try
      {
        return fDocument.get(start, end - start);
      }
      catch (BadLocationException x)
      {
        throw new IndexOutOfBoundsException(x.getLocalizedMessage());
      }
    }
  }
  
  private class InternalDocumentListener
    implements IDocumentListener
  {
    InternalDocumentListener(InternalDocumentListener paramInternalDocumentListener)
    {
      this();
    }
    
    public void documentChanged(DocumentEvent event) {}
    
    public void documentAboutToBeChanged(DocumentEvent event)
    {
      DocumentReader.this.handleDocumentAboutToBeChanged();
    }
    
    private InternalDocumentListener() {}
  }
  
  private int fOffset = 0;
  private IDocument fDocument;
  private IDocumentListener fDocumentListener = new InternalDocumentListener(null);
  
  public DocumentReader(IDocument document)
  {
    Assert.isNotNull(document);
    fDocument = document;
    fCharSequence = new DocumentCharSequence(fDocument);
    fDocument.addDocumentListener(fDocumentListener);
    fLength = fCharSequence.length();
  }
  
  public void close()
    throws IOException
  {
    synchronized (this)
    {
      fCharSequence = null;
    }
    releaseDocument();
  }
  
  private void handleDocumentAboutToBeChanged()
  {
    IDocument document = fDocument;
    if ((fCharSequence == null) || (document == null)) {
      return;
    }
    String content = document.get();
    synchronized (this)
    {
      if (fCharSequence == null) {
        return;
      }
      fCharSequence = content;
    }
    releaseDocument();
  }
  
  private synchronized void releaseDocument()
  {
    if (fDocument != null) {
      fDocument.removeDocumentListener(fDocumentListener);
    }
    fDocument = null;
    fDocumentListener = null;
  }
  
  public int read(char[] cbuf, int off, int len)
    throws IOException
  {
    int i = 0;
    try
    {
      for (; (i < len) && (fOffset < fLength); i++) {
        cbuf[(off + i)] = fCharSequence.charAt(fOffset++);
      }
      if (i > 0) {
        return i;
      }
      return -1;
    }
    catch (NullPointerException localNullPointerException)
    {
      throw new IOException(TextEditorMessages.DocumentInputStream_error_streamClosed);
    }
    catch (IndexOutOfBoundsException localIndexOutOfBoundsException) {}
    return i - 1;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.DocumentReader
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.source.ISharedTextColors;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.internal.editors.text.NLSUtility;
import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
import org.eclipse.ui.texteditor.AnnotationTypeLookup;
import org.eclipse.ui.texteditor.HyperlinkDetectorRegistry;
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
import org.eclipse.ui.texteditor.spelling.SpellingService;

public final class EditorsUI
{
  public static final String PLUGIN_ID = "org.eclipse.ui.editors";
  public static final String DEFAULT_TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor";
  public static final int CHARSET_MAPPING_FAILED = 1;
  public static final int STATE_VALIDATION_FAILED = 4;
  public static final int DERIVED_FILE = 5;
  
  public static AnnotationTypeLookup getAnnotationTypeLookup()
  {
    return EditorsPlugin.getDefault().getAnnotationTypeLookup();
  }
  
  public static AnnotationPreferenceLookup getAnnotationPreferenceLookup()
  {
    return EditorsPlugin.getDefault().getAnnotationPreferenceLookup();
  }
  
  public static IPreferenceStore getPreferenceStore()
  {
    return EditorsPlugin.getDefault().getPreferenceStore();
  }
  
  public static void useAnnotationsPreferencePage(IPreferenceStore store)
  {
    MarkerAnnotationPreferences.useAnnotationsPreferencePage(store);
  }
  
  public static void useQuickDiffPreferencePage(IPreferenceStore store)
  {
    MarkerAnnotationPreferences.useQuickDiffPreferencePage(store);
    
    store.setToDefault("quickdiff.quickDiff");
    store.setToDefault("quickdiff.characterMode");
    store.setToDefault("quickdiff.defaultProvider");
  }
  
  /**
   * @deprecated
   */
  public static Preferences getPluginPreferences()
  {
    return EditorsPlugin.getDefault().getPluginPreferences();
  }
  
  public static SpellingService getSpellingService()
  {
    return EditorsPlugin.getDefault().getSpellingService();
  }
  
  public static ISharedTextColors getSharedTextColors()
  {
    return EditorsPlugin.getDefault().getSharedTextColors();
  }
  
  public static HyperlinkDetectorRegistry getHyperlinkDetectorRegistry()
  {
    return EditorsPlugin.getDefault().getHyperlinkDetectorRegistry();
  }
  
  public static final String getTooltipAffordanceString()
  {
    if (!getPreferenceStore().getBoolean("showTextHoverAffordance")) {
      return null;
    }
    IBindingService bindingService = (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
    if (bindingService == null) {
      return null;
    }
    String keySequence = bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.edit.text.showInformation");
    if (keySequence == null) {
      return "";
    }
    return NLSUtility.format(TextEditorMessages.Editor_toolTip_affordance, keySequence);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.EditorsUI
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.jface.dialogs.IInputValidator;

class EncodingActionGroup$1
  implements IInputValidator
{
  final EncodingActionGroup.CustomEncodingAction this$1;
  
  EncodingActionGroup$1(EncodingActionGroup.CustomEncodingAction paramCustomEncodingAction)
  {
    this$1 = paramCustomEncodingAction;
  }
  
  public String isValid(String newText)
  {
    return (newText == null) || (newText.length() == 0) ? " " : null;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.EncodingActionGroup.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;

class EncodingActionGroup$2
  implements IMenuListener
{
  final EncodingActionGroup this$0;
  
  EncodingActionGroup$2(EncodingActionGroup paramEncodingActionGroup)
  {
    this$0 = paramEncodingActionGroup;
  }
  
  public void menuAboutToShow(IMenuManager manager)
  {
    this$0.update();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.EncodingActionGroup.2
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import java.util.ResourceBundle;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextEditorAction;

class EncodingActionGroup$CustomEncodingAction
  extends TextEditorAction
{
  protected EncodingActionGroup$CustomEncodingAction(ResourceBundle bundle, String prefix, ITextEditor editor)
  {
    super(bundle, prefix, editor);
  }
  
  public void update()
  {
    ITextEditor editor = getTextEditor();
    setEnabled((editor != null) && (!editor.isDirty()));
  }
  
  public void run()
  {
    ITextEditor editor = getTextEditor();
    if (editor == null) {
      return;
    }
    Class tmp14_11 = EncodingActionGroup.class$0;
    if (tmp14_11 == null)
    {
      tmp14_11;
      try
      {
        tmpTernaryOp = (EncodingActionGroup.class$0 = Class.forName("org.eclipse.ui.editors.text.IEncodingSupport"));
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
      }
    }
    IEncodingSupport encodingSupport = (IEncodingSupport)editor.getAdapter(tmp14_11);
    if (encodingSupport == null) {
      return;
    }
    String title = TextEditorMessages.Editor_ConvertEncoding_Custom_dialog_title;
    String message = TextEditorMessages.Editor_ConvertEncoding_Custom_dialog_message;
    IInputValidator inputValidator = new EncodingActionGroup.1(this);
    
    String initialValue = encodingSupport.getEncoding();
    if (initialValue == null) {
      initialValue = encodingSupport.getDefaultEncoding();
    }
    if (initialValue == null) {
      initialValue = "";
    }
    InputDialog d = new InputDialog(editor.getSite().getShell(), title, message, initialValue, inputValidator);
    if (d.open() == 0) {
      encodingSupport.setEncoding(d.getValue());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.EncodingActionGroup.CustomEncodingAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import java.util.ResourceBundle;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.TextEditorAction;

class EncodingActionGroup$PredefinedEncodingAction
  extends TextEditorAction
{
  private String fEncoding;
  private String fLabel;
  private boolean fIsDefault;
  
  public EncodingActionGroup$PredefinedEncodingAction(ResourceBundle bundle, String prefix, String encoding, ITextEditor editor)
  {
    super(bundle, prefix, editor);
    fEncoding = encoding;
    if (prefix == null) {
      setText(encoding);
    }
    fLabel = getText();
  }
  
  public EncodingActionGroup$PredefinedEncodingAction(ResourceBundle bundle, String encoding, ITextEditor editor)
  {
    super(bundle, null, editor);
    fEncoding = encoding;
    setText(encoding);
    fLabel = getText();
  }
  
  private IEncodingSupport getEncodingSupport()
  {
    ITextEditor editor = getTextEditor();
    if (editor != null)
    {
      Class tmp13_10 = EncodingActionGroup.class$0;
      if (tmp13_10 == null)
      {
        tmp13_10;
        try
        {
          tmpTernaryOp = (EncodingActionGroup.class$0 = Class.forName("org.eclipse.ui.editors.text.IEncodingSupport"));
        }
        catch (ClassNotFoundException localClassNotFoundException)
        {
          throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
        }
      }
      return (IEncodingSupport)editor.getAdapter(tmp13_10);
    }
    return null;
  }
  
  public void run()
  {
    IEncodingSupport s = getEncodingSupport();
    if (s != null) {
      s.setEncoding(fIsDefault ? null : fEncoding);
    }
  }
  
  private String getEncoding(ITextEditor editor)
  {
    IEditorInput input = editor.getEditorInput();
    if ((input instanceof IFileEditorInput))
    {
      IFile file = ((IFileEditorInput)input).getFile();
      try
      {
        String explicitEncoding = file.getCharset(false);
        if (explicitEncoding == null) {
          return null;
        }
      }
      catch (CoreException localCoreException) {}
    }
    IEncodingSupport s = getEncodingSupport();
    if (s != null) {
      return s.getEncoding();
    }
    return null;
  }
  
  public void update()
  {
    if (fEncoding == null)
    {
      setEnabled(false);
      return;
    }
    ITextEditor editor = getTextEditor();
    if (editor == null)
    {
      setEnabled(false);
      return;
    }
    fIsDefault = "default".equals(fEncoding);
    if (fIsDefault) {
      setText(EncodingActionGroup.access$0(editor, fLabel));
    } else {
      setText(fLabel);
    }
    if (editor.isDirty()) {
      setEnabled(false);
    } else {
      setEnabled(true);
    }
    String current = getEncoding(editor);
    if (fIsDefault) {
      setChecked(current == null);
    } else {
      setChecked(fEncoding.equals(current));
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ui.editors.text.EncodingActionGroup.PredefinedEncodingAction
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ui.editors.text;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.internal.editors.text.NLSUtility;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.IUpdate;
import org.eclipse.ui.texteditor.ResourceAction;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
import org.eclipse.ui.texteditor.TextEditorAction;

/**
 * @deprecated
 */
public class EncodingActionGroup
  extends ActionGroup
{
  private static final String FILE_CONTENT_ENCODING_FORMAT = TextEditorMessages.ResourceInfo_fileContentEncodingFormat;
  private static final String FILE_CONTAINER_ENCODING_FORMAT = TextEditorMessages.ResourceInfo_fileContainerEncodingFormat;
  private static final String[][] ENCODINGS;
  private static final String SYSTEM_ENCODING;
  
  static class PredefinedEncodingAction
    extends TextEditorAction
  {
    private String fEncoding;
    private String fLabel;
    private boolean fIsDefault;
    
    public PredefinedEncodingAction(ResourceBundle bundle, String prefix, String encoding, ITextEditor editor)
    {
      super(prefix, editor);
      fEncoding = encoding;
      if (prefix == null) {
        setText(encoding);
      }
      fLabel = getText();
    }
    
    public PredefinedEncodingAction(ResourceBundle bundle, String encoding, ITextEditor editor)
    {
      super(null, editor);
      fEncoding = encoding;
      setText(encoding);
      fLabel = getText();
    }
    
    private IEncodingSupport getEncodingSupport()
    {
      ITextEditor editor = getTextEditor();
      if (editor != null)
      {
        Class tmp13_10 = EncodingActionGroup.class$0;
        if (tmp13_10 == null)
        {
          tmp13_10;
          try
          {
            tmpTernaryOp = (EncodingActionGroup.class$0 = Class.forName("org.eclipse.ui.editors.text.IEncodingSupport"));
          }
          catch (ClassNotFoundException localClassNotFoundException)
          {
            throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
          }
        }
        return (IEncodingSupport)editor.getAdapter(tmp13_10);
      }
      return null;
    }
    
    public void run()
    {
      IEncodingSupport s = getEncodingSupport();
      if (s != null) {
        s.setEncoding(fIsDefault ? null : fEncoding);
      }
    }
    
    private String getEncoding(ITextEditor editor)
    {
      IEditorInput input = editor.getEditorInput();
      if ((input instanceof IFileEditorInput))
      {
        IFile file = ((IFileEditorInput)input).getFile();
        try
        {
          String explicitEncoding = file.getCharset(false);
          if (explicitEncoding == null) {
            return null;
          }
        }
        catch (CoreException localCoreException) {}
      }
      IEncodingSupport s = getEncodingSupport();
      if (s != null) {
        return s.getEncoding();
      }
      return null;
    }
    
    public void update()
    {
      if (fEncoding == null)
      {
        setEnabled(false);
        return;
      }
      ITextEditor editor = getTextEditor();
      if (editor == null)
      {
        setEnabled(false);
        return;
      }
      fIsDefault = "default".equals(fEncoding);
      if (fIsDefault) {
        setText(EncodingActionGroup.getDefaultEncodingText(editor, fLabel));
      } else {
        setText(fLabel);
      }
      if (editor.isDirty()) {
        setEnabled(false);
      } else {
        setEnabled(true);
      }
      String current = getEncoding(editor);
      if (fIsDefault) {
        setChecked(current == null);
      } else {
        setChecked(fEncoding.equals(current));
      }
    }
  }
  
  private static String getDefaultEncodingText(ITextEditor editor, String defaultText)
  {
    IEditorInput input = editor.getEditorInput();
    if (!(input instanceof IFileEditorInput)) {
      return defaultText;
    }
    IFile file = ((IFileEditorInput)input).getFile();
    
    String format = FILE_CONTENT_ENCODING_FORMAT;
    try
    {
      String encoding = getEncodingFromContent(file);
      if (encoding == null)
      {
        format = FILE_CONTAINER_ENCODING_FORMAT;
        encoding = file.getParent().getDefaultCharset();
      }
    }
    catch (CoreException localCoreException)
    {
      return defaultText;
    }
    String encoding;
    return NLSUtility.format(format, encoding);
  }
  
  private static String getEncodingFromContent(IFile file)
    throws CoreException
  {
    IContentDescription description = file.getContentDescription();
    if (description != null)
    {
      byte[] bom = (byte[])description.getProperty(IContentDescription.BYTE_ORDER_MARK);
      if (bom == null) {
        return (String)description.getProperty(IContentDescription.CHARSET);
      }
      if (bom == IContentDescription.BOM_UTF_8) {
        return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_8;
      }
      if (bom == IContentDescription.BOM_UTF_16BE) {
        return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_16BE;
      }
      if (bom == IContentDescription.BOM_UTF_16LE) {
        return TextEditorMessages.WorkbenchPreference_encoding_BOM_UTF_16LE;
      }
    }
    return null;
  }
  
  static class CustomEncodingAction
    extends TextEditorAction
  {
    protected CustomEncodingAction(ResourceBundle bundle, String prefix, ITextEditor editor)
    {
      super(prefix, editor);
    }
    
    public void update()
    {
      ITextEditor editor = getTextEditor();
      setEnabled((editor != null) && (!editor.isDirty()));
    }
    
    public void run()
    {
      ITextEditor editor = getTextEditor();
      if (editor == null) {
        return;
      }
      Class tmp14_11 = EncodingActionGroup.class$0;
      if (tmp14_11 == null)
      {
        tmp14_11;
        try
        {
          tmpTernaryOp = (EncodingActionGroup.class$0 = Class.forName("org.eclipse.ui.editors.text.IEncodingSupport"));
        }
        catch (ClassNotFoundException localClassNotFoundException)
        {
          throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
        }
      }
      IEncodingSupport encodingSupport = (IEncodingSupport)editor.getAdapter(tmp14_11);
      if (encodingSupport == null) {
        return;
      }
      String title = TextEditorMessages.Editor_ConvertEncoding_Custom_dialog_title;
      String message = TextEditorMessages.Editor_ConvertEncoding_Custom_dialog_message;
      IInputValidator inputValidator = new EncodingActionGroup.1(this);
      
      String initialValue = encodingSupport.getEncoding();
      if (initialValue == null) {
        initialValue = encodingSupport.getDefaultEncoding();
      }
      if (initialValue == null) {
        initialValue = "";
      }
      InputDialog d = new InputDialog(editor.getSite().getShell(), title, message, initialValue, inputValidator);
      if (d.open() == 0) {
        encodingSupport.setEncoding(d.getValue());
      }
    }
  }
  
  static
  {
    String[][] encodings = {
      { "default", "org.eclipse.ui.default_action_context", "org.eclipse.ui.edit.text.encoding.default" }, 
      { "US-ASCII", "org.eclipse.ui.US-ASCII_action_context", "org.eclipse.ui.edit.text.encoding.us-ascii" }, 
      { "ISO-8859-1", "org.eclipse.ui.ISO-8859-1_action_context", "org.eclipse.ui.edit.text.encoding.iso-8859-1" }, 
      { "UTF-8", "org.eclipse.ui.UTF-8_action_context", "org.eclipse.ui.edit.text.encoding.utf-8" }, 
      { "UTF-16BE", "org.eclipse.ui.UTF-16BE_action_context", "org.eclipse.ui.edit.text.encoding.utf-16be" }, 
      { "UTF-16LE", "org.eclipse.ui.UTF-16LE_action_context", "org.eclipse.ui.edit.text.encoding.utf-16le" }, 
      { "UTF-16", "org.eclipse.ui.UTF-16_action_context", "org.eclipse.ui.edit.text.encoding.utf-16" } };
    
    String system = System.getProperty("file.encoding");
    if (system != null)
    {
      for (int i = 0; i < encodings.length; i++) {
        if (encodings[i][0].equals(system)) {
          break;
        }
      }
      if (i != encodings.length)
      {
        String[] s = encodings[i];
        encodings[i] = encodings[1];
        encodings[1] = s;
        
        system = null;
      }
    }
    SYSTEM_ENCODING = system;
    ENCODINGS = encodings;
  }
  
  private List fRetargetActions = new ArrayList();
  private ITextEditor fTextEditor;
  static Class class$0;
  
  public EncodingActionGroup()
  {
    fRetargetActions.add(new RetargetTextEditorAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ConvertEncoding." + ENCODINGS[0][0] + ".", ENCODINGS[0][0], 8));
    if (SYSTEM_ENCODING != null) {
      fRetargetActions.add(new RetargetTextEditorAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ConvertEncoding.System.", "System", 8));
    }
    for (int i = 1; i < ENCODINGS.length; i++) {
      fRetargetActions.add(new RetargetTextEditorAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ConvertEncoding." + ENCODINGS[i][0] + ".", ENCODINGS[i][0], 8));
    }
    fRetargetActions.add(new RetargetTextEditorAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ConvertEncoding.Custom.", "Custom", 1));
  }
  
  public void fillActionBars(IActionBars actionBars)
  {
    IMenuManager menuManager = actionBars.getMenuManager();
    IMenuManager editMenu = menuManager.findMenuUsingPath("edit");
    if ((editMenu != null) && (fRetargetActions.size() > 0))
    {
      MenuManager subMenu = new MenuManager(TextEditorMessages.Editor_ConvertEncoding_submenu_label);
      subMenu.addMenuListener(new IMenuListener()
      {
        public void menuAboutToShow(IMenuManager manager)
        {
          update();
        }
      });
      Iterator e = fRetargetActions.iterator();
      subMenu.add((IAction)e.next());
      subMenu.add(new Separator());
      while (e.hasNext()) {
        subMenu.add((IAction)e.next());
      }
      editMenu.add(subMenu);
    }
  }
  
  public void retarget(ITextEditor editor)
  {
    fTextEditor = editor;
    Iterator e = fRetargetActions.iterator();
    while (e.hasNext())
    {
      RetargetTextEditorAction a = (RetargetTextEditorAction)e.next();
      a.setAction(editor == null ? null : editor.getAction(a.getId()));
    }
  }
  
  public EncodingActionGroup(ITextEditor editor)
  {
    fTextEditor = editor;
    if (SYSTEM_ENCODING != null)
    {
      ResourceAction a = new PredefinedEncodingAction(TextEditorMessages.getBundleForConstructedKeys(), SYSTEM_ENCODING, editor);
      a.setHelpContextId("org.eclipse.ui.System_action_context");
      a.setActionDefinitionId("org.eclipse.ui.edit.text.encoding.system");
      editor.setAction("System", a);
    }
    for (int i = 0; i < ENCODINGS.length; i++)
    {
      ResourceAction a = new PredefinedEncodingAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ConvertEncoding." + ENCODINGS[i][0] + ".", ENCODINGS[i][0], editor);
      a.setHelpContextId(ENCODINGS[i][1]);
      a.setActionDefinitionId(ENCODINGS[i][2]);
      editor.setAction(ENCODINGS[i][0], a);
    }
    ResourceAction a = new CustomEncodingAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ConvertEncoding.Custom.", editor);
    a.setHelpContextId("org.eclipse.ui.Custom_action_context");
    a.setActionDefinitionId("org.eclipse.ui.edit.text.encoding.custom");
    editor.setAction("Custom", a);
  }
  
  public void update()
  {
    if (fTextEditor == null) {
      return;
    }
    IAction a = fTextEditor.getAction("System");
    if ((a instanceof IUpdate)) {
      ((IUpdate)a).update();
    }
    for (int i = 0; i < ENCODINGS.length; i++)
    {
      a = fTextEditor.getAction(ENCODINGS[i][0]);
      if ((a instanceof IUpdate)) {
        ((IUpdate)a).update();
      }
    }
    a = fTextEditor.getAction("Custom");
    if ((a instanceof IUpdate)) {
      ((IUpdate)a).update();
    }
  }
  
  public void dispose()
  {
    if (fTextEditor != null)
    {
      fTextEditor.setAction("System", null);
      for (int i = 0; i < ENCODINGS.length; i++) {
        fTextEditor.setAction(EN
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

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-2019. Infinite Loop Ltd