Beispiel #1
0
 public void addTool(
     final NewStatsConfiguration newStatsConfiguration,
     ToolListView<IEquipmentStats> statsListView) {
   final Tool newTool = statsListView.addTool();
   newTool.setTooltip(resources.getString(newStatsConfiguration.getTooltipKey()));
   newTool.setIcon(newStatsConfiguration.getIconPath());
   newTool.setOverlay(new RelativePath("icons/ButtonPlus16.png"));
   newTool.setCommand(
       new Command() {
         @Override
         public void execute() {
           List<String> definedNames = new ArrayList<>();
           for (IEquipmentStats stats : editModel.getStats()) {
             definedNames.add(stats.getName().getId());
           }
           String nameProposal = resources.getString(newStatsConfiguration.getNameKey());
           String[] nameArray = definedNames.toArray(new String[definedNames.size()]);
           IEquipmentStats equipmentStats =
               statsFactory.createNewStats(
                   nameArray, nameProposal, newStatsConfiguration.getType());
           editModel.addStatistics(equipmentStats);
         }
       });
   controlAvailability(newStatsConfiguration, newTool);
   editModel.addCompositionChangeListener(
       new ChangeListener() {
         @Override
         public void changeOccurred() {
           controlAvailability(newStatsConfiguration, newTool);
         }
       });
 }
 private void initializeCommand() {
   interaction.setCommand(new CreateNewCommand());
 }
  @SuppressWarnings("serial")
  private void initEntryPresentation() {
    String labelText = resources.getString("Linguistics.SelectionView.Label");
    AgnosticUIConfiguration<Object> uiConfiguration = new LanguageUiConfiguration();
    final ObjectSelectionViewWithTool<Object> selectionView =
        view.addSelectionView(labelText, uiConfiguration);
    selectionView.setObjects(model.getPredefinedLanguages());
    selectionView.addObjectSelectionChangedListener(
        new ObjectValueListener<Object>() {
          @Override
          public void valueChanged(Object newValue) {
            if (newValue == null) {
              return;
            }
            Identifier definedLanguage = getLanguage(newValue);
            if (definedLanguage == null) {
              model.selectBarbarianLanguage(newValue.toString());
            } else {
              model.selectLanguage(definedLanguage);
            }
          }
        });
    final Tool addButton = selectionView.addTool();
    addButton.setIcon(new BasicUi().getAddIconPath());
    addButton.setCommand(
        new Command() {
          @Override
          public void execute() {
            if (!model.isEntryAllowed()) {
              return;
            }
            model.commitSelection();
          }
        });
    model.addModelChangeListener(
        new RemovableEntryListener<Identifier>() {
          @Override
          public void entryAdded(Identifier entry) {
            addEntry(entry);
            selectionView.setSelectedObject(null);
          }

          @Override
          public void entryAllowed(boolean complete) {
            selectionView.setSelectedObject(model.getSelectedEntry());
            if (complete) {
              addButton.enable();
            } else {
              addButton.disable();
            }
          }

          @Override
          public void entryRemoved(Identifier entry) {
            RemovableEntryView entryView = viewsByEntry.remove(entry);
            entryView.delete();
          }
        });
    for (Identifier language : model.getPredefinedLanguages()) {
      languagesByDisplayName.put(getDisplayString(language), language);
    }
    for (Identifier language : model.getEntries()) {
      addEntry(language);
    }
  }