patch

16:50:53.863 INFO  jd.cli.Main - Decompiling patch.jar
package org.eclipse.jst.pagedesigner.converter.html;

import org.eclipse.jst.jsf.common.ui.JSFUICommonPlugin;
import org.eclipse.jst.pagedesigner.converter.AbstractTagConverter;
import org.eclipse.jst.pagedesigner.converter.DumDescriptionTagConverter;
import org.eclipse.jst.pagedesigner.converter.DumTagConverter;
import org.eclipse.jst.pagedesigner.converter.HiddenTagConverter2;
import org.eclipse.jst.pagedesigner.converter.IConverterFactory;
import org.eclipse.jst.pagedesigner.converter.ITagConverter;
import org.eclipse.jst.pagedesigner.utils.HTMLUtil;
import org.eclipse.swt.graphics.Image;
import org.w3c.dom.Element;

public class HTMLConverterFactory
  implements IConverterFactory
{
  public ITagConverter createConverter(Element element, int mode)
  {
    String tagName = element.getLocalName();
    if (mode == 1) {
      return new DumTagConverter(element);
    }
    if (!HTMLUtil.isVisualHtmlElement(tagName)) {
      return new HiddenTagConverter2(element, getUnknownImage());
    }
    AbstractTagConverter c;
    AbstractTagConverter c;
    if ("table".equalsIgnoreCase(tagName))
    {
      c = new TableTagConverter(element);
    }
    else
    {
      AbstractTagConverter c;
      if ("a".equalsIgnoreCase(tagName))
      {
        c = new ATagConverter(element);
      }
      else
      {
        AbstractTagConverter c;
        if (("form".equalsIgnoreCase(tagName)) || 
          ("div".equalsIgnoreCase(tagName)))
        {
          c = new DumTagConverter(element, true);
        }
        else if (("html".equalsIgnoreCase(tagName)) || 
          ("body".equalsIgnoreCase(tagName)))
        {
          AbstractTagConverter c = new DumDescriptionTagConverter(element);
          c.setNeedBorderDecorator(true);
        }
        else
        {
          c = new DumTagConverter(element);
        }
      }
    }
    c.setMode(mode);
    return c;
  }
  
  private static Image getUnknownImage()
  {
    return JSFUICommonPlugin.getDefault().getImage(
      "PD_Palette_Default.gif");
  }
  
  public String getSupportedURI()
  {
    return "html";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.converter.html.HTMLConverterFactory
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.css2.property;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jst.pagedesigner.PDPlugin;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.eclipse.jst.pagedesigner.utils.DOMUtil;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.w3c.dom.Element;
import org.w3c.dom.css.CSSValue;

public class BackgroundImageMeta
  extends CSSPropertyMeta
{
  private static final String[] _keywords = { "none" };
  
  public BackgroundImageMeta()
  {
    super(false, "none");
  }
  
  public Object calculateCSSValueResult(CSSValue value, String propertyName, ICSSStyle style)
  {
    Object ret = null;
    String valueText = value.getCssText();
    if ((valueText != null) && (valueText.length() > 0))
    {
      valueText = stripURLSyntax(valueText);
      ret = getImage(valueText, null);
    }
    if (ret == null) {
      ret = getInitialValue(propertyName, style);
    }
    return ret;
  }
  
  public Object calculateHTMLAttributeOverride(Element element, String htmltag, String propertyName, ICSSStyle style)
  {
    Image image = null;
    if ((element != null) && 
      (element.getNodeName() != null) && 
      (element.getNodeName().equalsIgnoreCase("body")) && 
      ("background-image".equalsIgnoreCase(propertyName)))
    {
      String attrValue = DOMUtil.getAttributeIgnoreCase(element, "background");
      if ((attrValue != null) && (attrValue.trim().length() > 0)) {
        image = getImage(attrValue.trim(), element);
      }
    }
    return image;
  }
  
  protected String[] getKeywordValues()
  {
    return _keywords;
  }
  
  private String stripURLSyntax(String input)
  {
    String output = null;
    if (input != null)
    {
      int startPos = input.indexOf("url(") + 4;
      if ((startPos > -1) && (startPos < input.length() - 1))
      {
        int endPos = input.indexOf(')', startPos);
        if (endPos > startPos)
        {
          String insideURL = input.substring(startPos, endPos).trim();
          if ((insideURL.startsWith("\"")) && (insideURL.endsWith("\""))) {
            output = insideURL.substring(1, insideURL.length() - 1);
          } else if ((insideURL.startsWith("'")) && (insideURL.endsWith("'"))) {
            output = insideURL.substring(1, insideURL.length() - 1);
          } else {
            output = insideURL;
          }
        }
      }
    }
    return output != null ? output : input;
  }
  
  private Image getImage(String imagePath, Element element)
  {
    Image image = null;
    if ((imagePath != null) && (imagePath.length() > 0))
    {
      ImageRegistry registry = PDPlugin.getDefault().getImageRegistry();
      image = registry.get(imagePath);
      if (image == null)
      {
        try
        {
          URL imageURL = new URL(imagePath);
          ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(imageURL);
          image = imageDescriptor.createImage();
          if (image == null) {
            return image;
          }
          registry.put(imagePath, image);
        }
        catch (MalformedURLException localMalformedURLException1)
        {
          if (!(element instanceof IDOMNode)) {
            return image;
          }
          IDOMModel model = ((IDOMNode)element).getModel();
          if (model == null) {
            return image;
          }
          String baseLocation = model.getBaseLocation();
          if ((baseLocation == null) || (baseLocation.length() <= 0)) {
            return image;
          }
          IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
          if (wsRoot == null) {
            return image;
          }
          IResource jspRes = wsRoot.findMember(baseLocation);
          if (jspRes == null) {
            return image;
          }
          IContainer jspFolder = jspRes.getParent();
          if (jspFolder == null) {
            return image;
          }
          IResource imageRes = jspFolder.findMember(imagePath);
          if (imageRes == null) {
            return image;
          }
          URI imageURI = imageRes.getLocationURI();
          if (imageURI == null) {
            return image;
          }
          try
          {
            URL imageURL = imageURI.toURL();
            ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(imageURL);
            image = imageDescriptor.createImage();
            if (image == null) {
              return image;
            }
            registry.put(imagePath, image);
          }
          catch (MalformedURLException localMalformedURLException2) {}
        }
        catch (SWTException localSWTException) {}
      }
      else if (image.isDisposed())
      {
        registry.remove(imagePath);
        image = getImage(imagePath, element);
      }
    }
    return image;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.css2.property.BackgroundImageMeta
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.css2.widget;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jst.pagedesigner.css2.ICSSStyle;
import org.eclipse.jst.pagedesigner.css2.font.ICSSFont;
import org.eclipse.jst.pagedesigner.css2.layout.TextLayoutSupport;
import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo;
import org.eclipse.jst.pagedesigner.css2.style.DefaultStyle;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

public class TextAreaWidgetProvider
  extends AbstractWidgetProvider
{
  private static final int DEFAULTCOLUMN = 20;
  private static final int DEFAULTROWS = 2;
  private static final int VERTICAL_PADDING = 2;
  private static final int HORIZONTAL_PADDING = 2;
  private static int ARRAWWIDTH = 16;
  private static int ARROWHEIGHT = 16;
  private int _columns = 20;
  private int _rows = 2;
  private String _value;
  
  public TextAreaWidgetProvider(ICSSStyle style)
  {
    super(style);
  }
  
  public DimensionInfo getPreferredDimension(int width, int height)
  {
    if (width <= 0) {
      width = getDefaultWidth();
    }
    if (height <= 0) {
      height = getDefaultHeight();
    }
    return new DimensionInfo(width, height, -1);
  }
  
  private int getDefaultHeight()
  {
    ICSSStyle style = getCSSStyle();
    if (style == null) {
      style = DefaultStyle.getInstance();
    }
    ICSSFont font = style.getCSSFont();
    Font swtfont = font.getSwtFont();
    int fontHeight = FigureUtilities.getFontMetrics(swtfont).getHeight();
    
    return fontHeight * _rows + 2;
  }
  
  private int getDefaultWidth()
  {
    ICSSStyle style = getCSSStyle();
    if (style == null) {
      style = DefaultStyle.getInstance();
    }
    ICSSFont font = style.getCSSFont();
    
    int fontWidth = FigureUtilities.getFontMetrics(font.getSwtFont())
      .getAverageCharWidth();
    return _columns * fontWidth + ARRAWWIDTH + 2;
  }
  
  public void paintFigure(Graphics g, Rectangle rect)
  {
    if (_value != null)
    {
      g.clipRect(rect);
      ICSSStyle style = getCSSStyle();
      if (style == null) {
        style = DefaultStyle.getInstance();
      }
      int decoration = ((Integer)style
        .getStyleProperty("text-decoration"))
        .intValue();
      ICSSFont font = style.getCSSFont();
      g.setFont(font.getSwtFont());
      
      Color newColor = null;
      Object color = style.getColor();
      if ((color instanceof Color))
      {
        g.setForegroundColor((Color)color);
      }
      else if ((color instanceof RGB))
      {
        newColor = new Color(Display.getCurrent(), (RGB)color);
        g.setForegroundColor(newColor);
      }
      else
      {
        g.setForegroundColor(ColorConstants.black);
      }
      Object textAlign = style
        .getStyleProperty("text-align");
      int begin = 0;
      int end = 0;
      int fontHeight = FigureUtilities.getFontMetrics(font.getSwtFont())
        .getHeight();
      
      int fontWidth = FigureUtilities.getFontMetrics(font.getSwtFont())
        .getAverageCharWidth();
      int columns = (width - 2) / fontWidth;
      
      int i = 0;
      for (;;)
      {
        int y = y + 1 + fontHeight * i;
        if (y >= rect.bottom()) {
          break;
        }
        end += columns;
        if (end > _value.length()) {
          end = _value.length();
        }
        end = getTextCount(begin, end, g.getFont(), width - 
          ARRAWWIDTH);
        
        String text = _value.substring(begin, end);
        
        int width = FigureUtilities.getTextWidth(text, g.getFont());
        int x = TextLayoutSupport.getBeginX(textAlign, rect, width);
        g.drawString(text, x, y);
        
        TextLayoutSupport.paintTextDecoration(g, new Rectangle(x, y, 
          width, fontHeight), decoration);
        begin = end;
        if (end == _value.length()) {
          break;
        }
        i++;
      }
      if (newColor != null) {
        newColor.dispose();
      }
    }
    int borderThick = 2;
    
    BorderUtil.drawVertialBar(g, ARRAWWIDTH, ARROWHEIGHT, borderThick, rect);
  }
  
  private int getTextCount(int begin, int end, Font swtFont, int textWidth)
  {
    while (FigureUtilities.getTextWidth(_value.substring(begin, end), swtFont) > textWidth)
    {
      if (end == 0) {
        return end;
      }
      end--;
    }
    return end;
  }
  
  public void setColumns(int columns)
  {
    _columns = (columns > 0 ? columns : 20);
  }
  
  public void setRows(int rows)
  {
    _rows = (rows > 0 ? rows : 2);
  }
  
  public void setValue(String value)
  {
    _value = value;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.css2.widget.TextAreaWidgetProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.part.MultiPageSelectionProvider;

class HTMLEditor$1
  implements ISelectionChangedListener
{
  HTMLEditor$1(HTMLEditor paramHTMLEditor) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    ((MultiPageSelectionProvider)this$0.getSite().getSelectionProvider()).firePostSelectionChanged(event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.part.MultiPageSelectionProvider;

class HTMLEditor$2
  implements ISelectionChangedListener
{
  HTMLEditor$2(HTMLEditor paramHTMLEditor) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    ((MultiPageSelectionProvider)this$0.getSite().getSelectionProvider()).firePostSelectionChanged(event);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jst.pagedesigner.ui.common.sash.SashEditorPart;
import org.eclipse.ui.PartInitException;

class HTMLEditor$3
  extends SashEditorPart
{
  HTMLEditor$3(HTMLEditor paramHTMLEditor) {}
  
  protected void createPages()
    throws PartInitException
  {
    addPage(HTMLEditor.access$0(this$0), getEditorInput());
    addPage(HTMLEditor.access$1(this$0), getEditorInput());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;

class HTMLEditor$4
  implements ISelectionChangedListener
{
  HTMLEditor$4(HTMLEditor paramHTMLEditor) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    if (this$0.getActiveEditor() != HTMLEditor.access$1(this$0)) {
      HTMLEditor.access$0(this$0).getSynchronizer().selectionChanged(event);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.4
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;

class HTMLEditor$5
  implements ISelectionChangedListener
{
  HTMLEditor$5(HTMLEditor paramHTMLEditor) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    if (this$0.getActiveEditor() != HTMLEditor.access$1(this$0)) {
      HTMLEditor.access$0(this$0).getSynchronizer().selectionChanged(event);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.5
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;

class HTMLEditor$6
  implements ISelectionChangedListener
{
  HTMLEditor$6(HTMLEditor paramHTMLEditor) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    if ((event.getSelection() instanceof TextSelection))
    {
      TextSelection textSelection = (TextSelection)event
        .getSelection();
      HTMLEditor.access$0(this$0)
        .getSynchronizer()
        .textSelectionChanged(
        textSelection.getOffset(), 
        textSelection.getOffset() + 
        textSelection
        .getLength());
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.6
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;

class HTMLEditor$7
  implements ISelectionChangedListener
{
  HTMLEditor$7(HTMLEditor paramHTMLEditor) {}
  
  public void selectionChanged(SelectionChangedEvent event)
  {
    TextSelection textSelection = (TextSelection)event
      .getSelection();
    HTMLEditor.access$0(this$0).getSynchronizer()
      .textSelectionChanged(
      textSelection.getOffset(), 
      textSelection.getOffset() + 
      textSelection
      .getLength());
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.7
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import org.eclipse.jst.pagedesigner.ui.common.PartActivationHandler;
import org.eclipse.ui.IWorkbenchPart;

class HTMLEditor$8
  extends PartActivationHandler
{
  HTMLEditor$8(HTMLEditor paramHTMLEditor, IWorkbenchPart $anonymous0)
  {
    super($anonymous0);
  }
  
  public void handleActivation()
  {
    HTMLEditor.access$2(this$0);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.8
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

class HTMLEditor$9
  implements Runnable
{
  HTMLEditor$9(HTMLEditor paramHTMLEditor) {}
  
  public void run()
  {
    HTMLEditor.access$3(this$0, 1);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.jst.pagedesigner.editors.HTMLEditor.9
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.jst.pagedesigner.editors;

import java.io.File;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.gef.DefaultEditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.ui.views.palette.PalettePage;
import org.eclipse.gef.ui.views.palette.PaletteViewerPage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.IPostSelectionProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jst.jsf.common.ui.internal.logging.Logger;
import org.eclipse.jst.jsf.common.ui.internal.utils.ResourceUtils;
import org.eclipse.jst.pagedesigner.PDPlugin;
import org.eclipse.jst.pagedesigner.dnd.internal.DesignerSourceMouseTrackAdapter;
import org.eclipse.jst.pagedesigner.editors.pagedesigner.PageDesignerResources;
import org.eclipse.jst.pagedesigner.jsp.core.pagevar.IPageVariablesProvider;
import org.eclipse.jst.pagedesigner.jsp.core.pagevar.adapter.IDocumentPageVariableAdapter;
import org.eclipse.jst.pagedesigner.parts.DocumentEditPart;
import org.eclipse.jst.pagedesigner.preview.WindowsIEBrowser;
import org.eclipse.jst.pagedesigner.properties.WPETabbedPropertySheetPage;
import org.eclipse.jst.pagedesigner.tools.RangeSelectionTool;
import org.eclipse.jst.pagedesigner.ui.common.PartActivationHandler;
import org.eclipse.jst.pagedesigner.ui.common.sash.SashEditorPart;
import org.eclipse.jst.pagedesigner.ui.preferences.PDPreferences;
import org.eclipse.jst.pagedesigner.utils.EditorUtil;
import org.eclipse.jst.pagedesigner.viewer.IHTMLGraphicalViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.part.MultiPageEditorSite;
import org.eclipse.ui.part.MultiPageSelectionProvider;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.provisional.IDOMSourceEditingTextTools;
import org.w3c.dom.Document;

public final class HTMLEditor
  extends MultiPageEditorPart
  implements IPropertyListener, ITabbedPropertySheetPageContributor
{
  public static final String TABBED_PROPERTIES_CONTRIBUTOR_ID = "org.eclipse.jst.pagedesigner.tabPropertyContributor";
  public static final int MODE_SASH_VERTICAL = 0;
  public static final int MODE_SASH_HORIZONTAL = 1;
  public static final int MODE_DESIGNER = 2;
  public static final int MODE_SOURCE = 3;
  private Logger _log = PDPlugin.getLogger(HTMLEditor.class);
  private boolean _sash = true;
  private int _mode = 0;
  private SashEditorPart _sashEditorPart = null;
  private int _previewPageIndex;
  private SimpleGraphicalEditor _designViewer;
  private StructuredTextEditor _textEditor;
  private PartActivationHandler _partListener;
  private PaletteViewerPage _paletteViewerPage;
  private DefaultEditDomain _editDomain;
  private WindowsIEBrowser _browser;
  private Composite _previewComposite;
  private List PREVIEW_FILES_LIST = new ArrayList();
  private IPropertySheetPage _tabbedPropSheet;
  private ISelectionChangedListener _selChangedListener;
  
  private void _firePropertyChange(int property)
  {
    super.firePropertyChange(property);
  }
  
  public String getContributorId()
  {
    return "org.eclipse.jst.pagedesigner.tabPropertyContributor";
  }
  
  private void connectSashPage()
  {
    ISelectionProvider selectionProvider = _sashEditorPart.getSite()
      .getSelectionProvider();
    if ((selectionProvider instanceof IPostSelectionProvider)) {
      ((IPostSelectionProvider)selectionProvider).addPostSelectionChangedListener(getSelectionChangedListener(selectionProvider));
    } else {
      selectionProvider.addSelectionChangedListener(getSelectionChangedListener(selectionProvider));
    }
  }
  
  private void disconnectSashPage()
  {
    if ((_sashEditorPart != null) && 
      (_sashEditorPart.getSite() != null) && 
      (_sashEditorPart.getSite().getSelectionProvider() != null) && 
      (_selChangedListener != null))
    {
      ISelectionProvider selectionProvider = _sashEditorPart.getSite()
        .getSelectionProvider();
      if (selectionProvider != null) {
        if ((selectionProvider instanceof IPostSelectionProvider)) {
          ((IPostSelectionProvider)selectionProvider).removePostSelectionChangedListener(getSelectionChangedListener(selectionProvider));
        } else {
          selectionProvider.removeSelectionChangedListener(getSelectionChangedListener(selectionProvider));
        }
      }
    }
  }
  
  private ISelectionChangedListener getSelectionChangedListener(ISelectionProvider selectionProvider)
  {
    if (_selChangedListener == null) {
      if ((selectionProvider instanceof IPostSelectionProvider)) {
        _selChangedListener = new ISelectionChangedListener()
        {
          public void selectionChanged(SelectionChangedEvent event)
          {
            ((MultiPageSelectionProvider)getSite().getSelectionProvider()).firePostSelectionChanged(event);
          }
        };
      } else {
        _selChangedListener = new ISelectionChangedListener()
        {
          public void selectionChanged(SelectionChangedEvent event)
          {
            ((MultiPageSelectionProvider)getSite().getSelectionProvider()).firePostSelectionChanged(event);
          }
        };
      }
    }
    return _selChangedListener;
  }
  
  protected void sash_createAndAddDesignSourcePage()
    throws PartInitException
  {
    _textEditor = createTextEditor();
    _textEditor.setEditorPart(this);
    _textEditor.addPropertyListener(this);
    
    _designViewer = new SimpleGraphicalEditor(this, getEditDomain());
    
    _sashEditorPart = new SashEditorPart()
    {
      protected void createPages()
        throws PartInitException
      {
        addPage(_designViewer, getEditorInput());
        addPage(_textEditor, getEditorInput());
      }
    };
    int sashIndex = addPage(_sashEditorPart, getEditorInput());
    
    initDesignerMode();
    
    setPageText(sashIndex, PDPlugin.getResourceString("HTMLEditor.Design"));
    
    _textEditor.update();
    
    firePropertyChange(1);
    
    connectSashPage();
  }
  
  protected IEditorSite createSite(IEditorPart editor)
  {
    return new MultiPageEditorSite(this, editor);
  }
  
  private void tabbed_createAndAddDesignSourcePage()
    throws PartInitException
  {
    _textEditor = createTextEditor();
    _textEditor.setEditorPart(this);
    _textEditor.addPropertyListener(this);
    
    SimpleGraphicalEditor editor = new SimpleGraphicalEditor(this, 
      getEditDomain());
    
    int designPageIndex = addPage(editor, null);
    
    _designViewer = editor;
    
    setPageText(designPageIndex, 
      PDPlugin.getResourceString("HTMLEditor.Design"));
    
    int sourcePageIndex = addPage(_textEditor, getEditorInput());
    setPageText(sourcePageIndex, 
      PDPlugin.getResourceString("HTMLEditor.Source"));
    
    _textEditor.update();
    
    firePropertyChange(1);
  }
  
  private void createAndAddPreviewPage()
  {
    _previewComposite = new Composite(getContainer(), 0);
    FillLayout filllayout = new FillLayout();
    _previewComposite.setLayout(filllayout);
    
    _previewPageIndex = addPage(_previewComposite);
    
    setPageText(_previewPageIndex, PageDesignerResources.getInstance()
      .getString("JSPSourceEditor.Page.Preview.PageText"));
  }
  
  private WindowsIEBrowser getPreviewBrowser()
  {
    if (_browser == null)
    {
      _browser = new WindowsIEBrowser();
      if (_browser != null)
      {
        try
        {
          _browser.create(_previewComposite, 65536);
        }
        catch (Error localError)
        {
          _browser.create(_previewComposite, 0);
        }
        _previewComposite.layout();
      }
    }
    return _browser;
  }
  
  protected void connectDesignPage()
  {
    if (_designViewer != null)
    {
      _designViewer.setModel(getModel());
      
      ISelectionProvider designSelectionProvider = _designViewer
        .getSite().getSelectionProvider();
      if ((designSelectionProvider instanceof IPostSelectionProvider)) {
        ((IPostSelectionProvider)designSelectionProvider).addPostSelectionChangedListener(new ISelectionChangedListener()
        {
          public void selectionChanged(SelectionChangedEvent event)
          {
            if (getActiveEditor() != _textEditor) {
              _designViewer.getSynchronizer().selectionChanged(event);
            }
          }
        });
      } else {
        designSelectionProvider.addSelectionChangedListener(new ISelectionChangedListener()
        {
          public void selectionChanged(SelectionChangedEvent event)
          {
            if (getActiveEditor() != _textEditor) {
              _designViewer.getSynchronizer().selectionChanged(event);
            }
          }
        });
      }
      ISelectionProvider textSelectionProvider = _textEditor.getSite()
        .getSelectionProvider();
      if ((textSelectionProvider instanceof IPostSelectionProvider)) {
        ((IPostSelectionProvider)textSelectionProvider).addPostSelectionChangedListener(new ISelectionChangedListener()
        {
          public void selectionChanged(SelectionChangedEvent event)
          {
            if ((event.getSelection() instanceof TextSelection))
            {
              TextSelection textSelection = (TextSelection)event
                .getSelection();
              _designViewer
                .getSynchronizer()
                .textSelectionChanged(
                textSelection.getOffset(), 
                textSelection.getOffset() + 
                textSelection
                .getLength());
            }
          }
        });
      } else {
        textSelectionProvider.addSelectionChangedListener(new ISelectionChangedListener()
        {
          public void selectionChanged(SelectionChangedEvent event)
          {
            TextSelection textSelection = (TextSelection)event
              .getSelection();
            _designViewer.getSynchronizer()
              .textSelectionChanged(
              textSelection.getOffset(), 
              textSelection.getOffset() + 
              textSelection
              .getLength());
          }
        });
      }
    }
  }
  
  protected void createPages()
  {
    try
    {
      if (_sash) {
        sash_createAndAddDesignSourcePage();
      } else {
        tabbed_createAndAddDesignSourcePage();
      }
      connectDesignPage();
      
      DesignerSourceMouseTrackAdapter adapter = new DesignerSourceMouseTrackAdapter(
        _textEditor, getEditDomain());
      _textEditor.getTextViewer().getTextWidget().addMouseListener(
        adapter);
      _textEditor.getTextViewer().getTextWidget().addMouseMoveListener(
        adapter);
    }
    catch (PartInitException localPartInitException) {}
  }
  
  protected StructuredTextEditor createTextEditor()
  {
    return new DesignerStructuredTextEditorJSP();
  }
  
  private void disconnectDesignPage()
  {
    if (_designViewer != null)
    {
      _designViewer.setModel(null);
      _designViewer.dispose();
    }
  }
  
  public void dispose()
  {
    deletePreviewFiles();
    
    disconnectSashPage();
    disconnectDesignPage();
    
    IWorkbenchWindow window = getSite().getWorkbenchWindow();
    window.getPartService().removePartListener(_partListener);
    window.getShell().removeShellListener(_partListener);
    getSite().getPage().removePartListener(_partListener);
    if (_textEditor != null)
    {
      _textEditor.removePropertyListener(this);
      _textEditor.setEditorPart(null);
      _textEditor.dispose();
    }
    _sashEditorPart = null;
    _tabbedPropSheet = null;
    _partListener = null;
    _editDomain = null;
    _designViewer = null;
    _browser = null;
    _previewComposite = null;
    _paletteViewerPage = null;
    _log = null;
    _selChangedListener = null;
    _textEditor = null;
    
    super.dispose();
  }
  
  public void doSave(IProgressMonitor monitor)
  {
    _textEditor.doSave(monitor);
  }
  
  public void doSaveAs()
  {
    _textEditor.doSaveAs();
  }
  
  private void editorInputIsAcceptable(IEditorInput input)
    throws PartInitException
  {
    if ((input instanceof IFileEditorInput))
    {
      CoreException[] coreExceptionArray = new CoreException[1];
      if (fileDoesNotExist((IFileEditorInput)input, coreExceptionArray))
      {
        Throwable coreException = coreExceptionArray[0];
        if ((coreException instanceof CoreException))
        {
          try
          {
            ((IFileEditorInput)input).getFile().refreshLocal(0, 
              new NullProgressMonitor());
          }
          catch (CoreException ce)
          {
            if (_log != null) {
              _log.error("Error.HTMLEditor.0", ce);
            }
          }
          throw new PartInitException("Resource " + input.getName() + 
            " does not exist.");
        }
        throw new PartInitException("Editor could not be open on " + 
          input.getName());
      }
    }
    else if ((input instanceof IStorageEditorInput))
    {
      InputStream contents = null;
      try
      {
        contents = 
          ((IStorageEditorInput)input).getStorage().getContents();
        if (contents == null) {
          throw new PartInitException("Editor could not be open on " + 
            input.getName());
        }
      }
      catch (CoreException noStorageExc)
      {
        noStorageExc = noStorageExc;
        
        _log.error("Error.HTMLEditor.1", noStorageExc);
        
        ResourceUtils.ensureClosed(contents); return;
      }
      finally
      {
        ce = 
          finally;ResourceUtils.ensureClosed(contents);
        throw ce;
      }
      ResourceUtils.ensureClosed(contents);
    }
  }
  
  /* Error */
  protected boolean fileDoesNotExist(IFileEditorInput input, Throwable[] coreException)
  {
    // Byte code:
    //   0: iconst_0
    //   1: istore_3
    //   2: aconst_null
    //   3: astore 4
    //   5: aload_1
    //   6: invokeinterface 486 1 0
    //   11: ifeq +17 -> 28
    //   14: aload_1
    //   15: invokeinterface 405 1 0
    //   20: invokeinterface 490 1 0
    //   25: ifne +8 -> 33
    //   28: iconst_1
    //   29: istore_3
    //   30: goto +64 -> 94
    //   33: aload_1
    //   34: invokeinterface 405 1 0
    //   39: iconst_1
    //   40: invokeinterface 491 2 0
    //   45: astore 4
    //   47: goto +42 -> 89
    //   50: astore 5
    //   52: iconst_1
    //   53: istore_3
    //   54: aload_2
    //   55: iconst_0
    //   56: aload 5
    //   58: aastore
    //   59: aload_0
    //   60: getfield 62	org/eclipse/jst/pagedesigner/editors/HTMLEditor:_log	Lorg/eclipse/jst/jsf/common/ui/internal/logging/Logger;
    //   63: ldc_w 494
    //   66: aload 5
    //   68: invokevirtual 420	org/eclipse/jst/jsf/common/ui/internal/logging/Logger:error	(Ljava/lang/String;Ljava/lang/Throwable;)V
    //   71: aload 4
    //   73: invokestatic 464	org/eclipse/jst/jsf/common/ui/internal/utils/ResourceUtils:ensureClosed	(Ljava/io/InputStream;)V
    //   76: goto +18 -> 94
    //   79: astore 6
    //   81: aload 4
    //   83: invokestatic 464	org/eclipse/jst/jsf/common/ui/internal/utils/ResourceUtils:ensureClosed	(Ljava/io/InputStream;)V
    //   86: aload 6
    //   88: athrow
    //   89: aload 4
    //   91: invokestatic 464	org/eclipse/jst/jsf/common/ui/internal/utils/ResourceUtils:ensureClosed	(Ljava/io/InputStream;)V
    //   94: iload_3
    //   95: ireturn
    // Line number table:
    //   Java source line #608	-> byte code offset #0
    //   Java source line #609	-> byte code offset #2
    //   Java source line #610	-> byte code offset #5
    //   Java source line #611	-> byte code offset #28
    //   Java source line #615	-> byte code offset #33
    //   Java source line #617	-> byte code offset #50
    //   Java source line #620	-> byte code offset #52
    //   Java source line #621	-> byte code offset #54
    //   Java source line #623	-> byte code offset #59
    //   Java source line #627	-> byte code offset #71
    //   Java source line #626	-> byte code offset #79
    //   Java source line #627	-> byte code offset #81
    //   Java source line #628	-> byte code offset #86
    //   Java source line #627	-> byte code offset #89
    //   Java source line #630	-> byte code offset #94
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	96	0	this	HTMLEditor
    //   0	96	1	input	IFileEditorInput
    //   0	96	2	coreException	Throwable[]
    //   1	94	3	result	boolean
    //   3	87	4	inStream	InputStream
    //   50	17	5	e	CoreException
    //   79	8	6	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   33	47	50	org/eclipse/core/runtime/CoreException
    //   33	71	79	finally
  }
  
  public Object getAdapter(Class key)
  {
    Object result = null;
    if (key == IDesignViewer.class)
    {
      result = _designViewer;
    }
    else
    {
      if (key == PalettePage.class) {
        return getPaletteViewerPage();
      }
      if (key == IPropertySheetPage.class) {
        return getPropertySheetPage();
      }
      if (key == IContentOutlinePage.class)
      {
        if (_textEditor != null) {
          result = _textEditor.getAdapter(key);
        }
      }
      else
      {
        if (key == IPageVariablesProvider.class)
        {
          Object obj = ((IDOMModel)getModel()).getDocument().getAdapterFor(
            IDocumentPageVariableAdapter.class);
          if ((obj instanceof IPageVariablesProvider)) {
            return obj;
          }
          return null;
        }
        if (_textEditor != null) {
          result = _textEditor.getAdapter(key);
        }
      }
    }
    return result;
  }
  
  public IDocument getDocument()
  {
    if (getTextEditor() == null) {
      return null;
    }
    Object apapter = _textEditor.getAdapter(ISourceEditingTextTools.class);
    if (apapter != null) {
      return ((ISourceEditingTextTools)apapter).getDocument();
    }
    return null;
  }
  
  public Document getDOMDocument()
  {
    if (getTextEditor() == null) {
      return null;
    }
    Object adapter = _textEditor.getAdapter(ISourceEditingTextTools.class);
    if ((adapter instanceof IDOMSourceEditingTextTools)) {
      return ((IDOMSourceEditingTextTools)adapter).getDOMDocument();
    }
    return null;
  }
  
  public IEditorPart getEditorPart()
  {
    return this;
  }
  
  public IStructuredModel getModel()
  {
    IStructuredModel model = null;
    if (_textEditor != null) {
      model = ((DesignerStructuredTextEditorJSP)_textEditor).getModel();
    }
    return model;
  }
  
  public StructuredTextEditor getTextEditor()
  {
    return _textEditor;
  }
  
  public String getTitle()
  {
    String title = null;
    if (getTextEditor() == null)
    {
      if (getEditorInput() != null) {
        title = getEditorInput().getName();
      }
    }
    else {
      title = getTextEditor().getTitle();
    }
    if (title == null) {
      title = getPartName();
    }
    return title;
  }
  
  public void init(IEditorSite site, IEditorInput input)
1 2

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