Examples of IEncodingSupport


Examples of org.eclipse.ui.editors.text.IEncodingSupport

   * @see org.eclipse.jface.action.Action#run()
   */
  public void run() {
    final IResource resource= getResource();
    final Shell parentShell= getTextEditor().getSite().getShell();
    final IEncodingSupport encodingSupport= getEncodingSupport();
    if (resource == null && encodingSupport == null) {
      MessageDialog.openInformation(parentShell, fDialogTitle, TextEditorMessages.ChangeEncodingAction_message_noEncodingSupport);
      return;
    }

    Dialog dialog= new Dialog(parentShell) {
      private AbstractEncodingFieldEditor fEncodingEditor;
      private IPreferenceStore store= null;

      /*
       * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
       */
      protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText(fDialogTitle);
      }

      /*
       * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
       */
      protected Control createDialogArea(Composite parent) {
        Control composite= super.createDialogArea(parent);
        if (!(composite instanceof Composite)) {
          composite.dispose();
          composite= new Composite(parent, SWT.NONE);
        }

        GridLayout layout= new GridLayout();
        layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        parent.setLayout(layout);

        GridData data = new GridData(GridData.FILL_BOTH);
        composite.setLayoutData(data);
        composite.setFont(parent.getFont());

        DialogPage page= new MessageDialogPage((Composite)composite) {
          public void setErrorMessage(String newMessage) {
            super.setErrorMessage(newMessage);
            setButtonEnabledState(IDialogConstants.OK_ID, newMessage == null);
            setButtonEnabledState(APPLY_ID, newMessage == null);
          }

          private void setButtonEnabledState(int id, boolean state) {
            Button button= getButton(id);
            if (button != null)
              button.setEnabled(state);
          }
        };

        if (resource != null) {
          fEncodingEditor= new ResourceEncodingFieldEditor("", (Composite)composite, resource); //$NON-NLS-1$
          fEncodingEditor.setPage(page);
          fEncodingEditor.load();
        } else {
          fEncodingEditor= new EncodingFieldEditor(ENCODING_PREF_KEY, "", (Composite)composite); //$NON-NLS-1$
          store= new PreferenceStore();
          String defaultEncoding= encodingSupport.getDefaultEncoding();
          store.setDefault(ENCODING_PREF_KEY, defaultEncoding);
          String encoding= encodingSupport.getEncoding();
          if (encoding != null)
            store.setValue(ENCODING_PREF_KEY, encoding);
          fEncodingEditor.setPreferenceStore(store);

          fEncodingEditor.setPage(page);
          fEncodingEditor.load();

          if (encoding == null || encoding.equals(defaultEncoding) || encoding.length() == 0)
            fEncodingEditor.loadDefault();
        }

        return composite;
      }

      /*
       * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
       */
      protected void createButtonsForButtonBar(Composite parent) {
        createButton(parent, APPLY_ID, TextEditorMessages.ChangeEncodingAction_button_apply_label, false);
        super.createButtonsForButtonBar(parent);
      }

      /*
       * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
       */
      protected void buttonPressed(int buttonId) {
        if (buttonId == APPLY_ID)
          apply();
        else
          super.buttonPressed(buttonId);
      }

      /*
       * @see org.eclipse.jface.dialogs.Dialog#okPressed()
       */
      protected void okPressed() {
        apply();
        super.okPressed();
      }

      private void apply() {
        fEncodingEditor.store();

        if (resource == null) {
          String encoding= fEncodingEditor.getPreferenceStore().getString(fEncodingEditor.getPreferenceName());
          encodingSupport.setEncoding(encoding);
        }
      }
    };
    dialog.open();
  }
View Full Code Here

Examples of org.eclipse.ui.editors.text.IEncodingSupport

   *
   * @seeorg.eclipse.ui.editors.text.DefaultEncodingSupport#
   * getDefaultEncoding()
   */
  public String getDefaultEncoding() {
    IEncodingSupport delegate = getEncodingSupportDelegate();
    if (delegate != null) {
      return delegate.getDefaultEncoding();
    }

    return super.getDefaultEncoding();
  }
View Full Code Here

Examples of org.eclipse.ui.editors.text.IEncodingSupport

   * (non-Javadoc)
   *
   * @see org.eclipse.ui.editors.text.DefaultEncodingSupport#getEncoding ()
   */
  public String getEncoding() {
    IEncodingSupport delegate = getEncodingSupportDelegate();
    if (delegate != null) {
      return delegate.getEncoding();
    }

    return super.getEncoding();
  }
View Full Code Here

Examples of org.eclipse.ui.editors.text.IEncodingSupport

   */
  public void initialize(StatusTextEditor textEditor) {
    super.initialize(textEditor);
    fStatusTextEditor = textEditor;

    IEncodingSupport encodingSupportDelegate = getEncodingSupportDelegate();
    if (encodingSupportDelegate instanceof DefaultEncodingSupport) {
      ((DefaultEncodingSupport) encodingSupportDelegate).initialize(textEditor);
    }
  }
View Full Code Here

Examples of org.eclipse.ui.editors.text.IEncodingSupport

    }
    fSupportDelegate = null;

    fConfigurationPoints = configurationPoints;

    IEncodingSupport encodingSupportDelegate = getEncodingSupportDelegate();
    if (encodingSupportDelegate instanceof DefaultEncodingSupport) {
      ((DefaultEncodingSupport) encodingSupportDelegate).initialize(fStatusTextEditor);
    }
  }
View Full Code Here

Examples of org.eclipse.ui.editors.text.IEncodingSupport

   * (java.lang.String, boolean)
   */
  protected void setEncoding(String encoding, boolean overwrite) {
    super.setEncoding(encoding, overwrite);

    IEncodingSupport delegate = getEncodingSupportDelegate();
    if (delegate != null && overwrite) {
      delegate.setEncoding(encoding);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.