/**
   * Installs the given font in the preference store and optionally the font registry.
   *
   * @param definition the font definition
   * @param registry the font registry
   * @param store the preference store from which to set and obtain font data
   * @param setInRegistry whether the color should be put into the registry as well as having its
   *     default preference set
   */
  private static void installFont(
      FontDefinition definition, ITheme theme, IPreferenceStore store, boolean setInRegistry) {
    FontRegistry registry = theme.getFontRegistry();

    String id = definition.getId();
    String key = createPreferenceKey(theme, id);
    FontData[] prefFont = store != null ? PreferenceConverter.getFontDataArray(store, key) : null;
    FontData[] defaultFont = null;
    if (definition.getValue() != null) {
      defaultFont = definition.getValue();
    } else if (definition.getDefaultsTo() != null) {
      defaultFont =
          registry.filterData(
              registry.getFontData(definition.getDefaultsTo()),
              Workbench.getInstance().getDisplay());
    } else {
      // values pushed in from jface property files.  Very ugly.
      Display display = Workbench.getInstance().getDisplay();

      // If in high contrast, ignore the defaults in jface and use the default (system) font.
      // This is a hack to address bug #205474. See bug #228207 for a future fix.
      FontData[] fontData =
          JFaceResources.getFontRegistry()
              .getFontData(display.getHighContrast() ? JFaceResources.DEFAULT_FONT : id);
      defaultFont = registry.bestDataArray(fontData, display);
    }

    if (setInRegistry) {
      if (prefFont == null || prefFont == PreferenceConverter.FONTDATA_ARRAY_DEFAULT_DEFAULT) {
        prefFont = defaultFont;
      }

      if (prefFont != null) {
        registry.put(id, prefFont);
      }
    }

    if (defaultFont != null && store != null) {
      PreferenceConverter.setDefault(store, key, defaultFont);
    }
  }
  @Override
  public void createPartControl(Composite parent) {

    shell = parent.getShell();

    FontRegistry fontRegistry = new FontRegistry(parent.getShell().getDisplay());

    fontRegistry.put(
        "TC", new FontData[] {new FontData("Arial", 10, SWT.BOLD)}); // $NON-NLS-1$ //$NON-NLS-2$

    final Composite comp = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    layout.horizontalSpacing = 5;
    layout.verticalSpacing = 5;
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    comp.setLayout(layout);

    GridData gd;

    terminoConceptText = new Text(comp, SWT.BORDER | SWT.CENTER | SWT.READ_ONLY);
    terminoConceptText.setEditable(false);
    terminoConceptText.setFont(fontRegistry.get("TC")); // $NON-NLS-1$
    gd = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
    terminoConceptText.setLayoutData(gd);

    // terminologic composite

    Composite terminoComposite = new Composite(comp, SWT.NONE);
    layout = new GridLayout(1, true);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    terminoComposite.setLayout(layout);
    terminoComposite.setLayoutData(gd);
    terminoComposite.setBackground(terminologicColor);

    // terms in current language

    currentLanguageTerms = new Composite(terminoComposite, SWT.NONE);
    layout = new GridLayout(2, false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    currentLanguageTerms.setLayout(layout);
    currentLanguageTerms.setLayoutData(gd);

    termsTableViewer =
        new TableViewer(
            currentLanguageTerms, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    termsTableViewer.getTable().setLayoutData(gridData);
    termsTableViewer.getTable().setLinesVisible(true);
    termsTableViewer.getTable().setHeaderVisible(true);
    termsTableViewer.setContentProvider(new TermContentProvider());
    termsTableViewer.setSorter(new TermsTableViewerSorter());

    // Columns

    termColumn = new TableViewerColumn(termsTableViewer, SWT.NONE, 0);
    termColumn.getColumn().setText(Messages.getString("TerminologicalViewPart.13")); // $NON-NLS-1$
    termColumn.setLabelProvider(new TermLabelProvider());
    termColumn.getColumn().setAlignment(SWT.CENTER);

    termColumn
        .getColumn()
        .addSelectionListener(
            new SelectionAdapter() {

              public void widgetSelected(SelectionEvent e) {
                TermsTableViewerSorter sorter = new TermsTableViewerSorter();
                termsTableViewer.setSorter(sorter);
                termsTableViewer.getTable().setSortColumn(termColumn.getColumn());
                termsTableViewer.getTable().setSortDirection(directionTerm);
              }
            });

    languageColumn = new TableViewerColumn(termsTableViewer, SWT.CENTER, 1);
    languageColumn
        .getColumn()
        .setText(Messages.getString("TerminologicalViewPart.14")); // $NON-NLS-1$
    languageColumn.getColumn().setAlignment(SWT.CENTER);
    languageColumn.setLabelProvider(new DefaultLanguageLabelProvider());

    currentLanguageTerms.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent e) {
            Rectangle area = currentLanguageTerms.getClientArea();
            Point preferredSize = termsTableViewer.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            int width = area.width - 2 * termsTableViewer.getTable().getBorderWidth();
            if (preferredSize.y > area.height + termsTableViewer.getTable().getHeaderHeight()) {

              Point vBarSize = termsTableViewer.getTable().getVerticalBar().getSize();
              width -= vBarSize.x;
            }

            Point oldSize = termsTableViewer.getTable().getSize();

            if (oldSize.x > area.width) {
              termColumn.getColumn().setWidth(width * 80 / 100);
              languageColumn.getColumn().setWidth(width * 20 / 100);
              termsTableViewer.getTable().setSize(area.width, area.height);
            } else {

              termsTableViewer.getTable().setSize(area.width, area.height);
              termColumn.getColumn().setWidth(width * 80 / 100);
              languageColumn.getColumn().setWidth(width * 20 / 100);
            }
          }
        });

    Button addTermCurrentLg = new Button(currentLanguageTerms, SWT.PUSH);
    String imageId = org.dafoe.terminoontologiclevel.ui.Activator.NEW_IMG_ID;
    ImageDescriptor imgDesc =
        org.dafoe.terminoontologiclevel.ui.Activator.getDefault()
            .getImageRegistry()
            .getDescriptor(imageId);
    Image image = imgDesc.createImage();
    addTermCurrentLg.setImage(image);
    addTermCurrentLg.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));

    addTermCurrentLg.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            addTerm();
          }
        });

    Button removeTermCurrentLg = new Button(currentLanguageTerms, SWT.PUSH);
    imageId = org.dafoe.terminoontologiclevel.ui.Activator.REMOVE_IMG_ID;
    imgDesc =
        org.dafoe.terminoontologiclevel.ui.Activator.getDefault()
            .getImageRegistry()
            .getDescriptor(imageId);
    image = imgDesc.createImage();
    removeTermCurrentLg.setImage(image);
    removeTermCurrentLg.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));

    removeTermCurrentLg.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {

            removeTerm();
          }
        });

    // Sentences

    sentencesWidget = new SentenceWidget(comp, SWT.NONE);
    layout = new GridLayout(1, false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    sentencesWidget.setLayout(layout);
    sentencesWidget.setLayoutData(gd);
    sentencesWidget.setDeletionEventType(TerminologicalViewPart.SENTENCE_DELETED);
    sentencesWidget.addPropertyChangeListener(new SentenceDeletedChangeListener());

    // terms in other languages

    otherLanguageTerms = new Composite(terminoComposite, SWT.NONE);
    layout = new GridLayout(2, false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    otherLanguageTerms.setLayout(layout);
    otherLanguageTerms.setLayoutData(gd);

    termsOtherLgTableViewer =
        new TableViewer(
            otherLanguageTerms, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    termsOtherLgTableViewer.getTable().setLayoutData(gridData);
    termsOtherLgTableViewer.getTable().setLinesVisible(true);
    termsOtherLgTableViewer.getTable().setHeaderVisible(true);
    termsOtherLgTableViewer.setContentProvider(new TranslatedTermContentProvider());

    // Columns

    termLgColumn = new TableViewerColumn(termsOtherLgTableViewer, SWT.NONE, 0);
    termLgColumn
        .getColumn()
        .setText(Messages.getString("TerminologicalViewPart.17")); // $NON-NLS-1$
    termLgColumn.setLabelProvider(new TranslatedTermLabelProvider());

    termLgColumn
        .getColumn()
        .addSelectionListener(
            new SelectionAdapter() {

              public void widgetSelected(SelectionEvent e) {
                TanslatedTermsTableViewerSorter sorter =
                    new TanslatedTermsTableViewerSorter(TanslatedTermsTableViewerSorter.TERM_SORT);
                termsOtherLgTableViewer.setSorter(sorter);
                termsOtherLgTableViewer.getTable().setSortColumn(termLgColumn.getColumn());
                termsOtherLgTableViewer.getTable().setSortDirection(directionTransTerm);
              }
            });

    languagesColumn = new TableViewerColumn(termsOtherLgTableViewer, SWT.NONE, 1);
    languagesColumn
        .getColumn()
        .setText(Messages.getString("TerminologicalViewPart.18")); // $NON-NLS-1$
    languagesColumn.setLabelProvider(new OtherLanguageLabelProvider());

    languagesColumn
        .getColumn()
        .addSelectionListener(
            new SelectionAdapter() {

              public void widgetSelected(SelectionEvent e) {
                TanslatedTermsTableViewerSorter sorter =
                    new TanslatedTermsTableViewerSorter(TanslatedTermsTableViewerSorter.FLAG_SORT);
                termsOtherLgTableViewer.setSorter(sorter);
                termsOtherLgTableViewer.getTable().setSortColumn(languagesColumn.getColumn());
                termsOtherLgTableViewer.getTable().setSortDirection(directionTransTerm);
              }
            });

    otherLanguageTerms.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent e) {
            Rectangle area = otherLanguageTerms.getClientArea();
            Point preferredSize =
                termsOtherLgTableViewer.getTable().computeSize(SWT.DEFAULT, SWT.DEFAULT);
            int width = area.width - 2 * termsOtherLgTableViewer.getTable().getBorderWidth();
            if (preferredSize.y
                > area.height + termsOtherLgTableViewer.getTable().getHeaderHeight()) {

              Point vBarSize = termsOtherLgTableViewer.getTable().getVerticalBar().getSize();
              width -= vBarSize.x;
            }

            Point oldSize = termsOtherLgTableViewer.getTable().getSize();

            if (oldSize.x > area.width) {

              termLgColumn.getColumn().setWidth(width * 80 / 100);
              languagesColumn.getColumn().setWidth(width * 20 / 100);
              termsOtherLgTableViewer.getTable().setSize(area.width, area.height);
            } else {
              termsOtherLgTableViewer.getTable().setSize(area.width, area.height);
              termLgColumn.getColumn().setWidth(width * 80 / 100);
              languagesColumn.getColumn().setWidth(width * 20 / 100);
            }
          }
        });

    Button addTermOtherLg = new Button(otherLanguageTerms, SWT.PUSH);
    imageId = org.dafoe.terminoontologiclevel.ui.Activator.NEW_IMG_ID;
    imgDesc =
        org.dafoe.terminoontologiclevel.ui.Activator.getDefault()
            .getImageRegistry()
            .getDescriptor(imageId);
    image = imgDesc.createImage();
    addTermOtherLg.setImage(image);
    addTermOtherLg.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));

    addTermOtherLg.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {

            addTranslatedTerm();
          }
        });

    Button removeTermOtherLg = new Button(otherLanguageTerms, SWT.PUSH);
    imageId = org.dafoe.terminoontologiclevel.ui.Activator.REMOVE_IMG_ID;
    imgDesc =
        org.dafoe.terminoontologiclevel.ui.Activator.getDefault()
            .getImageRegistry()
            .getDescriptor(imageId);
    image = imgDesc.createImage();
    removeTermOtherLg.setImage(image);
    removeTermOtherLg.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));

    removeTermOtherLg.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {

            removeTranslatedTerm();
          }
        });

    //

    ControlerFactoryImpl.getTerminoOntoControler()
        .addPropertyChangeListener(
            ControlerFactoryImpl.currentTerminoConceptEvent,
            new PropertyChangeListener() {
              public void propertyChange(PropertyChangeEvent evt) {

                updateInformation();
              }
            });

    ControlerFactoryImpl.getTerminoOntoControler()
        .addPropertyChangeListener(
            ControlerFactoryImpl.renameTCEvent,
            new PropertyChangeListener() {
              public void propertyChange(PropertyChangeEvent evt) {

                updateInformation();
              }
            });

    makeActions();
    hookPopupMenus();

    updateInformation();
  }
示例#3
0
  private void createContent() {
    GridData gridData;

    Composite composite = new Composite(this, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    composite.setLayout(new GridLayout(3, false));

    FontRegistry fontRegistry = new FontRegistry(shell.getDisplay());
    fontRegistry.put(
        "WidgetTitle",
        new FontData[] {new FontData("Arial", 10, SWT.BOLD)}); // $NON-NLS-1$ //$NON-NLS-2$

    Label label = new Label(composite, SWT.NONE);
    label.setFont(fontRegistry.get("WidgetTitle")); // $NON-NLS-1$
    label.setText(Messages.getString("RTCTypeToRTTypeWidget.3")); // $NON-NLS-1$
    gridData = new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1);
    label.setLayoutData(gridData);

    Label titleBarSeparator = new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR);
    titleBarSeparator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Label currentTerminoRelationTypeLabel = new Label(composite, SWT.NONE);
    currentTerminoRelationTypeLabel.setText(
        Messages.getString("RTCTypeToRTTypeWidget.4") + " :"); // $NON-NLS-1$ //$NON-NLS-2$

    currentTerminoRelationTypeText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    currentTerminoRelationTypeText.setLayoutData(
        new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));

    Label associatedTypeLabel = new Label(composite, SWT.NONE);
    associatedTypeLabel.setLayoutData(
        new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 2));
    associatedTypeLabel.setText(
        Messages.getString("RTCTypeToRTTypeWidget.6") + " :"); // $NON-NLS-1$ //$NON-NLS-2$

    rtTypeListViewer = new ListViewer(composite, SWT.BORDER | SWT.V_SCROLL);
    rtTypeListViewer.setContentProvider(new RTTypeContentProvider());
    rtTypeListViewer.setLabelProvider(new RTLabelProvider());
    gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2);
    gridData.heightHint = 100;
    rtTypeListViewer.getList().setLayoutData(gridData);

    rtTypeListViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          public void selectionChanged(SelectionChangedEvent event) {

            IStructuredSelection selection = (IStructuredSelection) event.getSelection();

            if (selection.getFirstElement() != null) {

              unlinkAction.setEnabled(true);

              currentRTType = (ITypeRelationTermino) selection.getFirstElement();

              propertyChangeSupport.firePropertyChange(
                  rtTypeSelectionEventType, null, currentRTType);

            } else {

              unlinkAction.setEnabled(false);
            }
          }
        });

    Label newRTTypeLabel = new Label(composite, SWT.NONE);
    gridData = new GridData();
    gridData.verticalAlignment = SWT.CENTER;
    newRTTypeLabel.setLayoutData(gridData);
    newRTTypeLabel.setText(
        Messages.getString("RTCTypeToRTTypeWidget.8") + " :"); // $NON-NLS-1$ //$NON-NLS-2$

    newRTTypeText = new Text(composite, SWT.SINGLE | SWT.BORDER | SWT.WRAP);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.FILL;
    gridData.widthHint = 150;
    gridData.grabExcessHorizontalSpace = true;
    newRTTypeText.setLayoutData(gridData);

    Button newRTTypeButton = new Button(composite, SWT.NONE);
    String imageId = org.dafoe.terminologiclevel.Activator.NEW_IMG_ID;
    ImageDescriptor imgDesc =
        org.dafoe.terminologiclevel.Activator.getDefault()
            .getImageRegistry()
            .getDescriptor(imageId);
    Image imageAdd = imgDesc.createImage();
    newRTTypeButton.setImage(imageAdd);
    newRTTypeButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));

    newRTTypeButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {

            String newRTTypeLabel = newRTTypeText.getText().trim();
            ;

            if (newRTTypeLabel.compareTo("") != 0) { // $NON-NLS-1$

              ITypeRelationTermino testRTType = DatabaseAdapter.getRTTypeByLabel(newRTTypeLabel);

              // there isn't another RT type with the same label
              if (testRTType == null) {

                ITypeRelationTermino newRTType = DatabaseAdapter.createRelationType(newRTTypeLabel);

                org.dafoe.terminoontologiclevel.common.DatabaseAdapter.linkRTCTypeWithRTType(
                    currentRTCType, newRTType);

                newRTTypeText.setText(""); // $NON-NLS-1$

                updateContent(currentRTCType);

                propertyChangeSupport.firePropertyChange(newRTEventType, null, newRTType);

              } else {

                String msg =
                    Messages.getString("RTCTypeToRTTypeWidget.12")
                        + newRTTypeLabel
                        + Messages.getString(
                            "RTCTypeToRTTypeWidget.13"); //$NON-NLS-1$ //$NON-NLS-2$
                msg += Messages.getString("RTCTypeToRTTypeWidget.14"); // $NON-NLS-1$

                MessageDialog.openWarning(
                    shell, Messages.getString("RTCTypeToRTTypeWidget.15"), msg); // $NON-NLS-1$

                newRTTypeText.selectAll();
              }
            }
          }
        });

    composite.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            Rectangle rect = RTCTypeToRTTypeWidget.this.getClientArea();
            Image newImage = new Image(shell.getDisplay(), Math.max(1, rect.width), 1);
            GC gc = new GC(newImage);
            gc.setForeground(terminologic_level_color);
            gc.setBackground(terminoontologic_level_color);
            gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
            gc.dispose();
            RTCTypeToRTTypeWidget.this.setBackgroundImage(newImage);
            if (oldImage != null) {
              oldImage.dispose();
            }
            oldImage = newImage;
          }
        });

    makeActions();

    hookPopupMenu();
  }