public void preserveValues(final Widget widget) {
   ScrolledComposite composite = (ScrolledComposite) widget;
   ControlLCAUtil.preserveValues(composite);
   IWidgetAdapter adapter = WidgetUtil.getAdapter(composite);
   adapter.preserve(PROP_BOUNDS, composite.getBounds());
   adapter.preserve(PROP_OVERFLOW, getOverflow(composite));
   adapter.preserve(PROP_H_BAR_SELECTION, getBarSelection(composite.getHorizontalBar()));
   adapter.preserve(PROP_V_BAR_SELECTION, getBarSelection(composite.getVerticalBar()));
   adapter.preserve(Props.SELECTION_LISTENERS, Boolean.valueOf(hasSelectionListener(composite)));
   adapter.preserve(PROP_SHOW_FOCUSED_CONTROL, Boolean.valueOf(composite.getShowFocusedControl()));
   WidgetLCAUtil.preserveCustomVariant(composite);
 }
Example #2
0
 private static void writeCloseListener(final Shell shell) throws IOException {
   //    JSWriter writer = JSWriter.getWriterFor( shell );
   Boolean newValue = Boolean.valueOf(ShellEvent.hasListener(shell));
   Boolean defValue = Boolean.FALSE;
   //    writer.set( PROP_SHELL_LISTENER, "hasShellListener", newValue, defValue );
   boolean hasChanged = WidgetLCAUtil.hasChanged(shell, PROP_SHELL_LISTENER, newValue, defValue);
   if (hasChanged) {
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     if (newValue.booleanValue()) {
       synchronizer.addListener("closelistener");
     } else {
       synchronizer.removeListener("closelistener");
     }
   }
 }
Example #3
0
 public void preserveValues(final Widget widget) {
   ControlLCAUtil.preserveValues((Control) widget);
   Shell shell = (Shell) widget;
   IWidgetAdapter adapter = WidgetUtil.getAdapter(shell);
   adapter.preserve(PROP_ACTIVE_CONTROL, getActiveControl(shell));
   adapter.preserve(PROP_ACTIVE_SHELL, shell.getDisplay().getActiveShell());
   adapter.preserve(PROP_TEXT, shell.getText());
   adapter.preserve(PROP_IMAGE, shell.getImage());
   adapter.preserve(PROP_ALPHA, new Integer(shell.getAlpha()));
   adapter.preserve(PROP_MODE, getMode(shell));
   adapter.preserve(PROP_FULLSCREEN, Boolean.valueOf(shell.getFullScreen()));
   adapter.preserve(PROP_SHELL_LISTENER, Boolean.valueOf(ShellEvent.hasListener(shell)));
   adapter.preserve(PROP_SHELL_MENU, shell.getMenuBar());
   adapter.preserve(PROP_MINIMUM_SIZE, shell.getMinimumSize());
   WidgetLCAUtil.preserveCustomVariant(shell);
 }
Example #4
0
 private static void updateSelectionListener(final Tree tree) throws IOException {
   Boolean newValue = Boolean.valueOf(SelectionEvent.hasListener(tree));
   String prop = PROP_SELECTION_LISTENERS;
   if (WidgetLCAUtil.hasChanged(tree, prop, newValue, Boolean.FALSE)) {
     JSWriter writer = JSWriter.getWriterFor(tree);
     writer.set("selectionListeners", newValue);
   }
 }
Example #5
0
 public void preserveValues(final Widget widget) {
   Tree tree = (Tree) widget;
   ControlLCAUtil.preserveValues((Control) widget);
   IWidgetAdapter adapter = WidgetUtil.getAdapter(tree);
   adapter.preserve(PROP_SELECTION_LISTENERS, Boolean.valueOf(SelectionEvent.hasListener(tree)));
   adapter.preserve(PROP_HEADER_HEIGHT, new Integer(tree.getHeaderHeight()));
   adapter.preserve(PROP_HEADER_VISIBLE, Boolean.valueOf(tree.getHeaderVisible()));
   int[] values = tree.getColumnOrder();
   Integer[] columnOrder = new Integer[values.length];
   for (int i = 0; i < values.length; i++) {
     columnOrder[i] = new Integer(values[i]);
   }
   adapter.preserve(PROP_COLUMN_ORDER, columnOrder);
   adapter.preserve(PROP_SCROLL_LEFT, getScrollLeft(tree));
   adapter.preserve(PROP_HAS_H_SCROLL_BAR, hasHScrollBar(tree));
   adapter.preserve(PROP_HAS_V_SCROLL_BAR, hasVScrollBar(tree));
   WidgetLCAUtil.preserveCustomVariant(tree);
 }
 private static void writeShowFocusedControl(final ScrolledComposite composite)
     throws IOException {
   Boolean newValue = Boolean.valueOf(composite.getShowFocusedControl());
   String prop = PROP_SHOW_FOCUSED_CONTROL;
   if (WidgetLCAUtil.hasChanged(composite, prop, newValue, Boolean.FALSE)) {
     JSWriter writer = JSWriter.getWriterFor(composite);
     writer.set("showFocusedControl", newValue);
   }
 }
 private static void writeSelectionListener(final ScrolledComposite composite) throws IOException {
   boolean hasListener = hasSelectionListener(composite);
   Boolean newValue = Boolean.valueOf(hasListener);
   String prop = Props.SELECTION_LISTENERS;
   if (WidgetLCAUtil.hasChanged(composite, prop, newValue, Boolean.FALSE)) {
     JSWriter writer = JSWriter.getWriterFor(composite);
     writer.set("hasSelectionListener", newValue);
   }
 }
Example #8
0
 private static void writeFullScreen(final Shell shell) throws IOException {
   Object defValue = Boolean.FALSE;
   Boolean newValue = Boolean.valueOf(shell.getFullScreen());
   if (WidgetLCAUtil.hasChanged(shell, PROP_FULLSCREEN, newValue, defValue)) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     //      writer.set( "fullScreen", newValue );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.setWidgetProperty("fullScreen", newValue);
   }
 }
Example #9
0
 private static void writeOpen(final Shell shell) throws IOException {
   // TODO [rst] workaround: qx window should be opened only once.
   Boolean defValue = Boolean.FALSE;
   Boolean actValue = Boolean.valueOf(shell.getVisible());
   if (WidgetLCAUtil.hasChanged(shell, Props.VISIBLE, actValue, defValue) && shell.getVisible()) {
     //      JSWriter writer = JSWriter.getWriterFor( shell );
     //      writer.call( "open", null );
     IWidgetSynchronizer synchronizer = WidgetSynchronizerFactory.getSynchronizerForWidget(shell);
     synchronizer.call("open");
   }
 }
 static String getLibraryName(String mozillaPath) {
   /*
    * The name of the Gecko library to glue to changed between the XULRunner 10 and
    * 24 releases.  However it's not possible to programmatically know the version
    * of a XULRunner that's being used before it has been glued.  To determine the
    * appropriate Gecko library name to return, look for the presence of an "xpcom"
    * library in the mozilla path, which is present in all supported XULRunner releases
    * prior to XULRunner 24.  If this library is there then return it, and if it's not
    * there then assume that XULRunner 24 is being used and return the new library name
    * instead ("xul").
    */
   if (IsXULRunner24 == null) {
       /* IsXULRunner24 not yet initialized */
     IsXULRunner24 = new File(mozillaPath, LIB_XPCOM).exists() ? Boolean.FALSE : Boolean.TRUE;
   }
   return IsXULRunner24.booleanValue() ? LIB_XUL : LIB_XPCOM;
 }
Example #11
0
  public void modelChanged(IModelChangedEvent e) {
    // No need to call super, handling world changed event here
    if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
      handleModelEventWorldChanged(e);
      return;
    }

    String prop = e.getChangedProperty();
    Object[] objects = e.getChangedObjects();
    if (prop == null || objects == null || !(objects[0] instanceof IProduct)) return;
    if (prop.equals(IProduct.P_UID)) {
      fIdEntry.setValue(e.getNewValue().toString(), true);
    } else if (prop.equals(IProduct.P_NAME)) {
      fNameEntry.setValue(e.getNewValue().toString(), true);
    } else if (prop.equals(IProduct.P_VERSION)) {
      fVersionEntry.setValue(e.getNewValue().toString(), true);
    } else if (prop.equals(IProduct.P_INCLUDE_LAUNCHERS)) {
      fLaunchersButton.setSelection(Boolean.valueOf(e.getNewValue().toString()).booleanValue());
    }
  }
Example #12
0
 private static Boolean hasVScrollBar(final Tree tree) {
   Object adapter = tree.getAdapter(ITreeAdapter.class);
   ITreeAdapter treeAdapter = (ITreeAdapter) adapter;
   return Boolean.valueOf(treeAdapter.hasVScrollBar());
 }
Example #13
0
 private static void writeHeaderVisible(final Tree tree) throws IOException {
   JSWriter writer = JSWriter.getWriterFor(tree);
   Boolean newValue = Boolean.valueOf(tree.getHeaderVisible());
   writer.set(PROP_HEADER_VISIBLE, "headerVisible", newValue, Boolean.FALSE);
 }
public abstract class AbstractSchemaDetails extends PDEDetails {

  protected static final String[] BOOLS =
      new String[] {Boolean.toString(true), Boolean.toString(false)};

  protected int minLabelWeight;

  private Section fSection;
  private SchemaDtdDetailsSection fDtdSection = null;
  private ElementSection fElementSection;
  private boolean fShowDTD;
  private boolean fShowDescription;
  private Spinner fMinOccurSpinner;
  private Spinner fMaxOccurSpinner;
  private Button fUnboundSelect;
  private Label fMinLabel;
  private Label fMaxLabel;
  private PDESourceViewer fDescriptionViewer = null;
  private boolean fBlockListeners = false;
  private ISchemaObject fSchemaObject;

  public AbstractSchemaDetails(ElementSection section, boolean showDTD, boolean showDescription) {
    fElementSection = section;
    fShowDTD = showDTD;
    fShowDescription = showDescription;
  }

  @Override
  public void modelChanged(IModelChangedEvent event) {
    if ((event.getChangeType() == IModelChangedEvent.REMOVE)
        || (fShowDTD == false)
        || (fDtdSection == null)) {
      return;
    }
    Object[] objects = event.getChangedObjects();
    for (int i = 0; i < objects.length; i++) {
      if (objects[i] instanceof ISchemaCompositor) fDtdSection.updateDTDLabel(objects[i]);
    }
  }

  @Override
  public final void createContents(Composite parent) {
    // This is a hacked fix to ensure that the label columns on every details
    // page have the same width. SchemaDetails_translatable plus 11 pixels
    // represents the longest label on any field on any details page. This
    // occurs on SchemaStringAttributeDetails and 11 is the size of the
    // horizontal indent that contributes to the label's width.
    GC gc = new GC(parent);
    minLabelWeight = gc.textExtent(PDEUIMessages.SchemaDetails_translatable).x + 11;
    gc.dispose();
    gc = null;

    parent.setLayout(FormLayoutFactory.createDetailsGridLayout(false, 1));
    FormToolkit toolkit = getManagedForm().getToolkit();
    fSection = toolkit.createSection(parent, Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    fSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING;
    fSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));

    GridData gd;
    if (fShowDescription) gd = new GridData(GridData.FILL_BOTH);
    else gd = new GridData(GridData.FILL_HORIZONTAL);
    fSection.setLayoutData(gd);

    // Align the master and details section headers (misalignment caused
    // by section toolbar icons)
    getPage().alignSectionHeaders(fElementSection.getSection(), fSection);

    Composite client = toolkit.createComposite(fSection);
    client.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 3));

    createDetails(client);

    if (fShowDescription) createDescription(client, toolkit);

    // If the DTD Approximation section was requested, instantiate it and create it's contents
    // on the same parent Composite
    if (fShowDTD) {
      fDtdSection = new SchemaDtdDetailsSection();
      fDtdSection.initialize(getManagedForm());
      fDtdSection.createContents(parent);
    }

    toolkit.paintBordersFor(client);
    fSection.setClient(client);
    markDetailsPart(fSection);

    if (fShowDescription) fDescriptionViewer.createUIListeners();
    hookListeners();
  }

  private void createDescription(Composite container, FormToolkit toolkit) {

    Label label =
        toolkit.createLabel(container, PDEUIMessages.AbstractSchemaDetails_descriptionLabel);
    GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    gd.horizontalSpan = 3;
    label.setLayoutData(gd);
    label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));

    fDescriptionViewer = new PDESourceViewer(getPage());
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 75;
    gd.widthHint = 60;
    gd.horizontalSpan = 3;
    gd.horizontalIndent = 1;
    /*
     * Needed to align vertically with form entry field and allow space
     * for a possible field decoration
     * commented out for now since fields are already grossly misaligned (see bug 196879)
     * commenting out temporarily makes the alignment better on Element details and Attribute details
     * but worse on RootElement details
     */
    // gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
    fDescriptionViewer.createUI(container, gd);
    fDescriptionViewer
        .getDocument()
        .addDocumentListener(
            new IDocumentListener() {
              @Override
              public void documentChanged(DocumentEvent event) {
                if (blockListeners()) return;
                if (fSchemaObject != null) {
                  // Get the text from the event
                  IDocument document = event.getDocument();
                  if (document == null) {
                    return;
                  }
                  // Get the text from the event
                  String text = document.get().trim();
                  updateObjectDescription(text);
                }
              }

              @Override
              public void documentAboutToBeChanged(DocumentEvent event) {}
            });
  }

  public abstract void createDetails(Composite parent);

  public abstract void updateFields(ISchemaObject obj);

  public abstract void hookListeners();

  public boolean isEditableElement() {
    return fElementSection.isEditable();
  }

  protected void setDecription(String desc) {
    fSection.setDescription(desc);
  }

  protected void setText(String title) {
    fSection.setText(title);
  }

  @Override
  public String getContextId() {
    return SchemaInputContext.CONTEXT_ID;
  }

  @Override
  public PDEFormPage getPage() {
    return (PDEFormPage) getManagedForm().getContainer();
  }

  @Override
  public boolean isEditable() {
    return getPage().getPDEEditor().getAggregateModel().isEditable();
  }

  @Override
  public void fireSaveNeeded() {
    markDirty();
    getPage().getPDEEditor().fireSaveNeeded(getContextId(), false);
  }

  @Override
  public boolean canPaste(Clipboard clipboard) {
    if (fShowDescription
        && fDescriptionViewer != null
        && fDescriptionViewer.getViewer().getTextWidget().isFocusControl())
      return fDescriptionViewer.canPaste();
    return super.canPaste(clipboard);
  }

  @Override
  public boolean doGlobalAction(String actionId) {
    if (fShowDescription
        && fDescriptionViewer != null
        && fDescriptionViewer.getViewer().getTextWidget().isFocusControl())
      return fDescriptionViewer.doGlobalAction(actionId);
    return super.doGlobalAction(actionId);
  }

  @Override
  public void selectionChanged(IFormPart part, ISelection selection) {
    if (!(part instanceof ElementSection)) return;
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (obj instanceof ISchemaObject) {
      setBlockListeners(true);
      ISchemaObject sObj = (ISchemaObject) obj;
      fSchemaObject = sObj;
      if (fShowDTD && fDtdSection != null) fDtdSection.updateDTDLabel(obj);
      if (fShowDescription && fDescriptionViewer != null) updateDescriptionViewer(sObj);
      updateFields(sObj);
      setBlockListeners(false);
    }
  }

  public void updateDescriptionViewer(ISchemaObject obj) {
    if (obj != null) {
      String text = obj.getDescription();
      fDescriptionViewer.getDocument().set(text == null ? "" : text); // $NON-NLS-1$
      fDescriptionViewer.getViewer().setEditable(obj.getSchema().isEditable());
    }
  }

  private void updateObjectDescription(String text) {
    if (fSchemaObject instanceof SchemaObject) {
      ((SchemaObject) fSchemaObject).setDescription(text);
    }
  }

  protected void fireSelectionChange() {
    fElementSection.fireSelection(fElementSection.getTreeViewer().getSelection());
  }

  protected void fireMasterSelection(ISelection selection) {
    fElementSection.fireSelection(selection);
  }

  protected ComboPart createComboPart(
      Composite parent, FormToolkit toolkit, String[] items, int colspan, int style) {
    ComboPart cp = new ComboPart();
    cp.createControl(parent, toolkit, SWT.READ_ONLY);
    GridData gd = new GridData(style);
    gd.horizontalSpan = colspan;
    gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
    cp.getControl().setLayoutData(gd);
    cp.setItems(items);
    cp.getControl().setEnabled(isEditable());
    return cp;
  }

  protected ComboPart createComboPart(
      Composite parent, FormToolkit toolkit, String[] items, int colspan) {
    return createComboPart(parent, toolkit, items, colspan, GridData.FILL_HORIZONTAL);
  }

  protected Button[] createTrueFalseButtons(Composite parent, FormToolkit toolkit, int colSpan) {
    Composite comp = toolkit.createComposite(parent, SWT.NONE);
    GridLayout gl = new GridLayout(2, false);
    gl.marginHeight = gl.marginWidth = 0;
    comp.setLayout(gl);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = colSpan;
    gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT;
    comp.setLayoutData(gd);
    Button tButton = toolkit.createButton(comp, BOOLS[0], SWT.RADIO);
    Button fButton = toolkit.createButton(comp, BOOLS[1], SWT.RADIO);
    gd = new GridData();
    gd.horizontalIndent = 20;
    fButton.setLayoutData(gd);
    return new Button[] {tButton, fButton};
  }

  protected Composite createMinOccurComp(Composite parent, FormToolkit toolkit) {
    fMinLabel = toolkit.createLabel(parent, PDEUIMessages.AbstractSchemaDetails_minOccurLabel);
    fMinLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    Composite comp = toolkit.createComposite(parent);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = 0;
    comp.setLayout(layout);
    comp.setLayoutData(gd);
    fMinOccurSpinner = new Spinner(comp, SWT.BORDER);
    fMinOccurSpinner.setMinimum(0);
    fMinOccurSpinner.setMaximum(999);
    return comp;
  }

  protected Composite createMaxOccurComp(Composite parent, FormToolkit toolkit) {
    fMaxLabel = toolkit.createLabel(parent, PDEUIMessages.AbstractSchemaDetails_maxOccurLabel);
    fMaxLabel.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
    Composite comp = toolkit.createComposite(parent);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    GridLayout layout = new GridLayout(3, false);
    layout.marginHeight = layout.marginWidth = 0;
    comp.setLayout(layout);
    comp.setLayoutData(gd);

    fMaxOccurSpinner = new Spinner(comp, SWT.BORDER);
    fMaxOccurSpinner.setMinimum(1);
    fMaxOccurSpinner.setMaximum(999);
    fMaxOccurSpinner.setIncrement(1);

    fUnboundSelect =
        toolkit.createButton(comp, PDEUIMessages.AbstractSchemaDetails_unboundedButton, SWT.CHECK);
    gd = new GridData();
    gd.horizontalIndent = 10;
    fUnboundSelect.setLayoutData(gd);
    fUnboundSelect.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (blockListeners()) return;
            fMaxOccurSpinner.setEnabled(!fUnboundSelect.getSelection() && isEditableElement());
          }
        });

    return comp;
  }

  protected int getMinOccur() {
    if (fMinOccurSpinner != null) return fMinOccurSpinner.getSelection();
    return 0;
  }

  protected int getMaxOccur() {
    if (fMaxOccurSpinner != null) {
      if (fMaxOccurSpinner.isEnabled()) return fMaxOccurSpinner.getSelection();
      return Integer.MAX_VALUE;
    }
    return 1;
  }

  protected void updateMinOccur(int min) {
    if (fMinOccurSpinner != null) fMinOccurSpinner.setSelection(min);
  }

  protected void updateMaxOccur(int max) {
    if (fMaxOccurSpinner == null) return;
    boolean isMax = max == Integer.MAX_VALUE;
    fUnboundSelect.setSelection(isMax);
    fMaxOccurSpinner.setEnabled(!isMax);
    if (!isMax) fMaxOccurSpinner.setSelection(max);
  }

  protected void hookMinOccur(SelectionAdapter adapter) {
    fMinOccurSpinner.addSelectionListener(adapter);
    fMinOccurSpinner.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (blockListeners()) return;
            int minOccur = fMinOccurSpinner.getSelection();
            if (minOccur > getMaxOccur()) fMinOccurSpinner.setSelection(minOccur - 1);
          }
        });
  }

  protected void hookMaxOccur(SelectionAdapter adapter) {
    fUnboundSelect.addSelectionListener(adapter);
    fMaxOccurSpinner.addSelectionListener(adapter);
    fMaxOccurSpinner.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (blockListeners()) return;
            int maxValue = fMaxOccurSpinner.getSelection();
            if (maxValue < getMinOccur()) fMaxOccurSpinner.setSelection(maxValue + 1);
          }
        });
  }

  protected void enableMinMax(boolean enable) {
    fMinOccurSpinner.setEnabled(enable);
    fMaxOccurSpinner.setEnabled(!fUnboundSelect.getSelection() && enable);
    fUnboundSelect.setEnabled(enable);
    fMinLabel.setEnabled(enable);
    fMaxLabel.setEnabled(enable);
  }

  protected boolean blockListeners() {
    return fBlockListeners;
  }

  protected void setBlockListeners(boolean blockListeners) {
    fBlockListeners = blockListeners;
  }

  @Override
  public void dispose() {
    // Set the context menu to null to prevent the editor context menu
    // from being disposed along with the source viewer
    if (fDescriptionViewer != null) {
      fDescriptionViewer.unsetMenu();
      fDescriptionViewer = null;
    }
    super.dispose();
  }
}