Ejemplo n.º 1
0
 @Override
 protected Control createContents(Composite parent) {
   Control contents = super.createContents(parent);
   setTitle(Resources.getMessage("AboutDialog.12")); // $NON-NLS-1$
   setMessage(Resources.getMessage("AboutDialog.13"), IMessageProvider.INFORMATION); // $NON-NLS-1$
   if (image != null) setTitleImage(image); // $NON-NLS-1$
   return contents;
 }
Ejemplo n.º 2
0
  /**
   * Creates the design of this page
   *
   * <p>This adds all the controls to the page along with their listeners. It basically waits for
   * any radio button to be pressed, which will mark the page as completed and lets the user proceed
   * to the next page.
   *
   * @param parent
   */
  public void createControl(Composite parent) {

    Composite container = new Composite(parent, SWT.NULL);

    setControl(container);
    container.setLayout(new GridLayout(1, false));

    /* Add button for CSV */
    btnCsv = new Button(container, SWT.RADIO);
    btnCsv.setText(Resources.getMessage("ImportWizardPageSource.3")); // $NON-NLS-1$
    btnCsv.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent arg0) {
            wizardImport.getData().setSourceType(SourceType.CSV);
            setPageComplete(true);
          }
        });

    /* Add button for Excel */
    btnExcel = new Button(container, SWT.RADIO);
    btnExcel.setText(Resources.getMessage("ImportWizardPageSource.4")); // $NON-NLS-1$
    btnExcel.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent arg0) {
            wizardImport.getData().setSourceType(SourceType.EXCEL);
            setPageComplete(true);
          }
        });

    /* Add button for JDBC */
    btnJdbc = new Button(container, SWT.RADIO);
    btnJdbc.setText(Resources.getMessage("ImportWizardPageSource.5")); // $NON-NLS-1$
    btnJdbc.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent arg0) {
            wizardImport.getData().setSourceType(SourceType.JDBC);
            setPageComplete(true);
          }
        });

    /* Preselect CSV source*/
    btnCsv.setSelection(true);
    wizardImport.getData().setSourceType(SourceType.CSV);
    setPageComplete(true);
  }
Ejemplo n.º 3
0
  /**
   * Creates the view.
   *
   * @param root
   */
  private void create(final Composite root) {

    root.setLayout(new FillLayout());

    Tree tree = new Tree(root, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    tree.setHeaderVisible(true);

    treeViewer = new TreeViewer(tree);
    tree.setMenu(new ClipboardHandlerTree(treeViewer).getMenu());

    final TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    tree.setLinesVisible(true);
    column1.setAlignment(SWT.LEFT);
    column1.setText(Resources.getMessage("PropertiesView.3")); // $NON-NLS-1$
    column1.setWidth(160);
    final TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT);
    column2.setAlignment(SWT.LEFT);
    column2.setText(Resources.getMessage("PropertiesView.4")); // $NON-NLS-1$
    column2.setWidth(100);
    final TreeColumn column6 = new TreeColumn(tree, SWT.RIGHT);
    column6.setAlignment(SWT.LEFT);
    column6.setText(Resources.getMessage("PropertiesView.5")); // $NON-NLS-1$
    column6.setWidth(100);
    final TreeColumn column7 = new TreeColumn(tree, SWT.RIGHT);
    column7.setAlignment(SWT.LEFT);
    column7.setText(Resources.getMessage("PropertiesView.101")); // $NON-NLS-1$
    column7.setWidth(80);
    final TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
    column3.setAlignment(SWT.LEFT);
    column3.setText(Resources.getMessage("PropertiesView.6")); // $NON-NLS-1$
    column3.setWidth(50);
    final TreeColumn column4 = new TreeColumn(tree, SWT.RIGHT);
    column4.setAlignment(SWT.LEFT);
    column4.setText(Resources.getMessage("PropertiesView.7")); // $NON-NLS-1$
    column4.setWidth(50);
    final TreeColumn column5 = new TreeColumn(tree, SWT.RIGHT);
    column5.setAlignment(SWT.LEFT);
    column5.setText(Resources.getMessage("PropertiesView.8")); // $NON-NLS-1$
    column5.setWidth(50);
    final TreeColumn column8 = new TreeColumn(tree, SWT.RIGHT);
    column8.setAlignment(SWT.LEFT);
    column8.setText(Resources.getMessage("PropertiesView.113")); // $NON-NLS-1$
    column8.setWidth(50);
    final TreeColumn column9 = new TreeColumn(tree, SWT.RIGHT);
    column9.setAlignment(SWT.LEFT);
    column9.setText(Resources.getMessage("PropertiesView.126")); // $NON-NLS-1$
    column9.setWidth(50);

    treeViewer.setContentProvider(new InputContentProvider());
    treeViewer.setLabelProvider(new InputLabelProvider());

    treeViewer.setInput(roots);
    treeViewer.expandAll();
  }
Ejemplo n.º 4
0
  private void createLabels() {

    // Add status labels
    infoItem = new ToolItem(toolbar, SWT.SEPARATOR);
    infoComposite = new Composite(toolbar, SWT.NONE);
    infoItem.setControl(infoComposite);
    infoComposite.setLayout(null);

    labelAttribute = new Label(infoComposite, SWT.SINGLE | SWT.READ_ONLY);
    labelAttribute.setText(Resources.getMessage("MainToolBar.33")); // $NON-NLS-1$
    labelAttribute.pack();
    labelTransformations = new Label(infoComposite, SWT.SINGLE | SWT.READ_ONLY);
    labelTransformations.setText(Resources.getMessage("MainToolBar.33")); // $NON-NLS-1$
    labelTransformations.pack();
    labelSelected = new Label(infoComposite, SWT.SINGLE | SWT.READ_ONLY);
    labelSelected.setText(Resources.getMessage("MainToolBar.31")); // $NON-NLS-1$
    labelSelected.pack();
    labelApplied = new Label(infoComposite, SWT.SINGLE | SWT.READ_ONLY);
    labelApplied.setText(Resources.getMessage("MainToolBar.32")); // $NON-NLS-1$
    labelApplied.pack();

    // Copy info to clip board on right-click
    Menu menu = new Menu(toolbar);
    MenuItem itemCopy = new MenuItem(menu, SWT.NONE);
    itemCopy.setText(Resources.getMessage("MainToolBar.42")); // $NON-NLS-1$
    itemCopy.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent arg0) {
            if (tooltip != null) {
              Clipboard clipboard = new Clipboard(toolbar.getDisplay());
              TextTransfer textTransfer = TextTransfer.getInstance();
              clipboard.setContents(new String[] {tooltip}, new Transfer[] {textTransfer});
              clipboard.dispose();
            }
          }
        });
    labelSelected.setMenu(menu);
    labelApplied.setMenu(menu);
    labelTransformations.setMenu(menu);

    // Add listener for layout
    toolbar.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(final ControlEvent arg0) {
            layout();
          }
        });
  }
Ejemplo n.º 5
0
  /**
   * Creates a new instance of this page and sets its title and description.
   *
   * @param wizardImport Reference to wizard containing this page
   */
  public ImportWizardPageCSV(ImportWizard wizardImport) {

    super("WizardImportCsvPage"); // $NON-NLS-1$
    setTitle("CSV"); // $NON-NLS-1$
    setDescription(Resources.getMessage("ImportWizardPageCSV.6")); // $NON-NLS-1$
    this.wizardImport = wizardImport;
  }
Ejemplo n.º 6
0
  /**
   * Creates a new data import wizard and sets the window title.
   *
   * @param controller Reference to controller
   * @param model Reference to model
   */
  public ImportWizard(Controller controller, Model model) {

    setWindowTitle(Resources.getMessage("ImportWizard.0")); // $NON-NLS-1$
    this.setDefaultPageImageDescriptor(
        ImageDescriptor.createFromImage(
            controller.getResources().getManagedImage("import.png"))); // $NON-NLS-1$
    this.data = new ImportWizardModel(model);
    this.controller = controller;
    this.model = model;
  }
Ejemplo n.º 7
0
  /**
   * Evaluates the page
   *
   * <p>This checks whether the current settings on the page make any sense. If everything is fine,
   * the settings are being put into the appropriate data container {@link ImportWizardModel} and
   * the current page is marked as complete by invoking {@link #setPageComplete(boolean)}. Otherwise
   * an error message is set, which will make sure the user is informed about the reason for the
   * error.
   */
  private void evaluatePage() {

    setPageComplete(false);
    setErrorMessage(null);
    tablePreview.setVisible(false);

    if (comboLocation.getText().equals("")) { // $NON-NLS-1$
      return;
    }

    try {
      if (!customLinebreak) {
        detectLinebreak();
        comboLinebreak.select(selectedLinebreak);
      }
      if (!customDelimiter) {
        detectDelimiter();
        comboDelimiter.select(selectedDelimiter);
      }
      readPreview();

    } catch (IOException | IllegalArgumentException e) {
      setErrorMessage(e.getMessage());
      return;
    } catch (TextParsingException e) {
      setErrorMessage(Resources.getMessage("ImportWizardPageCSV.16")); // $NON-NLS-1$
      return;
    } catch (RuntimeException e) {
      if (e.getCause() != null) {
        setErrorMessage(e.getCause().getMessage());
      } else {
        setErrorMessage(e.getMessage());
      }
      return;
    }

    /* Put data into container */
    ImportWizardModel data = wizardImport.getData();

    data.setWizardColumns(wizardColumns);
    data.setPreviewData(previewData);
    data.setFirstRowContainsHeader(btnContainsHeader.getSelection());
    data.setFileLocation(comboLocation.getText());
    data.setCsvDelimiter(delimiters[selectedDelimiter]);
    data.setCsvQuote(quotes[selectedQuote]);
    data.setCsvEscape(escapes[selectedEscape]);
    data.setCharset(
        Charsets.getCharsetForName(Charsets.getNamesOfAvailableCharsets()[selectedCharset]));
    data.setCsvLinebreak(
        CSVSyntax.getLinebreakForLabel(CSVSyntax.getAvailableLinebreaks()[selectedLinebreak]));

    /* Mark page as completed */
    setPageComplete(true);
  }
Ejemplo n.º 8
0
 /**
  * Returns the current hierarchy.
  *
  * @return
  */
 public Hierarchy getHierarchy() {
   if (type == Type.INTERVAL_BASED) {
     return intervalModel.getHierarchy();
   } else if (type == Type.REDACTION_BASED) {
     return redactionModel.getHierarchy();
   } else if (type == Type.ORDER_BASED) {
     return orderModel.getHierarchy();
   } else {
     throw new RuntimeException(Resources.getMessage("HierarchyWizardModel.1")); // $NON-NLS-1$
   }
 }
Ejemplo n.º 9
0
 /**
  * Creates a pop up menu for this handler.
  *
  * @return
  */
 public Menu getMenu() {
   Menu menu = new Menu(tree.getTree());
   MenuItem itemCopy = new MenuItem(menu, SWT.NONE);
   itemCopy.setText(Resources.getMessage("ClipboardHandlerTree.0")); // $NON-NLS-1$
   itemCopy.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent arg0) {
           copy();
         }
       });
   return menu;
 }
Ejemplo n.º 10
0
 /**
  * Returns the current builder.
  *
  * @param serializable
  * @return
  * @throws Exception
  */
 public HierarchyBuilder<T> getBuilder(boolean serializable) throws Exception {
   if (type == Type.INTERVAL_BASED) {
     return intervalModel.getBuilder(serializable);
   } else if (type == Type.REDACTION_BASED) {
     return redactionModel.getBuilder(serializable);
   } else if (type == Type.ORDER_BASED) {
     return orderModel.getBuilder(serializable);
   } else {
     throw new IllegalArgumentException(
         Resources.getMessage("HierarchyWizardModel.0")); // $NON-NLS-1$
   }
 }
Ejemplo n.º 11
0
  @Override
  protected void createButtonsForButtonBar(final Composite parent) {

    // Create OK Button
    parent.setLayoutData(SWTUtil.createFillGridData());
    final Button okButton =
        createButton(
            parent, Window.OK, Resources.getMessage("AboutDialog.15"), true); // $NON-NLS-1$
    okButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            setReturnCode(Window.OK);
            close();
          }
        });
  }
Ejemplo n.º 12
0
  /**
   * Updates the model with a new specification.
   *
   * @param builder
   * @throws IllegalArgumentException
   */
  public void parse(HierarchyBuilder<T> builder) throws IllegalArgumentException {

    if (builder.getType() == Type.INTERVAL_BASED) {
      if (intervalModel != null) {
        this.intervalModel.parse((HierarchyBuilderIntervalBased<T>) builder);
        this.type = Type.INTERVAL_BASED;
      }
    } else if (builder.getType() == Type.ORDER_BASED) {
      this.orderModel.parse((HierarchyBuilderOrderBased<T>) builder);
      this.type = Type.ORDER_BASED;
    } else if (builder.getType() == Type.REDACTION_BASED) {
      this.redactionModel.parse(builder);
      this.type = Type.REDACTION_BASED;
    } else {
      throw new IllegalArgumentException(
          Resources.getMessage("HierarchyWizardModel.2")); // $NON-NLS-1$
    }
  }
Ejemplo n.º 13
0
    @Override
    public String toString() {

      // Prepare
      double prunedPercentage =
          (double) this.numTransformationsPruned
              / (double) this.numMaterializedTransformations
              * 100d;

      double materializedPercentage =
          (double) this.numMaterializedTransformations
              / (double) this.numTransformationsInSearchSpace
              * 100d;

      // Render statistics about the solution space
      StringBuilder sb = new StringBuilder();
      sb.append(Resources.getMessage("MainToolBar.1")); // $NON-NLS-1$
      sb.append(Resources.getMessage("MainToolBar.2")) // $NON-NLS-1$
          .append(this.numTransformationsInSearchSpace)
          .append("\n"); // $NON-NLS-1$

      sb.append(Resources.getMessage("MainToolBar.41")) // $NON-NLS-1$
          .append(this.numMaterializedTransformations);
      sb.append(" [") // $NON-NLS-1$
          .append(SWTUtil.getPrettyString(materializedPercentage))
          .append("%]\n"); // $NON-NLS-1$

      sb.append(Resources.getMessage("MainToolBar.12")) // $NON-NLS-1$
          .append(this.numTransformationsPruned);
      sb.append(" [") // $NON-NLS-1$
          .append(SWTUtil.getPrettyString(prunedPercentage))
          .append("%]\n"); // $NON-NLS-1$

      sb.append(Resources.getMessage("MainToolBar.18")) // $NON-NLS-1$
          .append(SWTUtil.getPrettyString(this.executionTime))
          .append("s\n"); // $NON-NLS-1$

      if (this.numTransformationsAnonymous != 0
          || this.numTransformationsNotAnonymous != 0
          || this.numTransformationsProbablyAnonymous != 0
          || this.numTransformationsProbablyNotAnonymous != 0
          || this.numTransformationsAnonymityUnknown != 0
          || this.numTransformationsInfolossAvailable != 0) {

        // Render the classification result
        sb.append(Resources.getMessage("MainToolBar.22")); // $NON-NLS-1$
        if (this.numTransformationsAnonymous != 0) {
          sb.append(Resources.getMessage("MainToolBar.24")) // $NON-NLS-1$
              .append(this.numTransformationsAnonymous);
        }
        if (this.numTransformationsNotAnonymous != 0) {
          sb.append(Resources.getMessage("MainToolBar.26")) // $NON-NLS-1$
              .append(this.numTransformationsNotAnonymous);
        }
        if (this.numTransformationsProbablyAnonymous != 0) {
          sb.append(Resources.getMessage("MainToolBar.28")) // $NON-NLS-1$
              .append(this.numTransformationsProbablyAnonymous);
        }
        if (this.numTransformationsProbablyNotAnonymous != 0) {
          sb.append(Resources.getMessage("MainToolBar.30")) // $NON-NLS-1$
              .append(this.numTransformationsProbablyNotAnonymous);
        }
        if (this.numTransformationsAnonymityUnknown != 0) {
          sb.append(Resources.getMessage("MainToolBar.34")) // $NON-NLS-1$
              .append(this.numTransformationsAnonymityUnknown);
        }
        if (this.numTransformationsInfolossAvailable != 0) {
          sb.append(Resources.getMessage("MainToolBar.35")) // $NON-NLS-1$
              .append(this.numTransformationsInfolossAvailable);
        }
        sb.append("\n");
      }
      // Render information about the optimum
      if (this.optimum != null) {
        sb.append(Resources.getMessage("MainToolBar.36")) // $NON-NLS-1$
            .append(Resources.getMessage("MainToolBar.39")) // $NON-NLS-1$
            .append(
                heuristic
                    ? Resources.getMessage("MainToolBar.60")
                    : Resources.getMessage("MainToolBar.61")) // $NON-NLS-1$ //$NON-NLS-2$
            .append(Resources.getMessage("MainToolBar.37")) // $NON-NLS-1$
            .append(Arrays.toString(optimum.getTransformation()));
        sb.append(Resources.getMessage("MainToolBar.38")) // $NON-NLS-1$
            .append(optimum.getMaximumInformationLoss().toString());
      }

      // Return
      return sb.toString();
    }
Ejemplo n.º 14
0
  /**
   * Update the view.
   *
   * @param part
   */
  protected void doUpdate(ModelPart part) {

    // Check model
    if (model == null) {
      return;
    }

    // Obtain definition
    DataDefinition definition = model.getOutputDefinition();
    if (definition == null) definition = model.getInputDefinition();

    // Obtain relevant configuration objects;
    ModelConfiguration config = null;
    Metric<?> metric = null;
    if (model.getOutputConfig() != null) {
      config = model.getOutputConfig();
      metric = config.getMetric();

      // We don't need to update in many cases, if we are displaying an output configuration
      if (part == ModelPart.ATTRIBUTE_TYPE
          || part == ModelPart.METRIC
          || part == ModelPart.ATTRIBUTE_WEIGHT
          || part == ModelPart.GS_FACTOR
          || part == ModelPart.MAX_OUTLIERS
          || part == ModelPart.DATA_TYPE
          || part == ModelPart.FINANCIAL_MODEL) {
        return;
      }

    } else {
      config = model.getInputConfig();
      // TODO: This is such an ugly hack
      metric = model.getMetricDescription().createInstance(model.getMetricConfiguration());
    }

    // Check
    if (definition == null || config == null || model.getInputConfig().getInput() == null) {
      reset();
      return;
    }

    // Obtain handle
    DataHandle data = model.getInputConfig().getInput().getHandle();

    // Disable redrawing
    root.setRedraw(false);

    // Clear
    roots.clear();

    // Print basic properties
    new Property(
        Resources.getMessage("PropertiesView.9"),
        new String[] {String.valueOf(data.getNumRows())}); // $NON-NLS-1$
    new Property(
        Resources.getMessage("PropertiesView.10"),
        new String[] {
          SWTUtil.getPrettyString(config.getAllowedOutliers() * 100d)
              + Resources.getMessage("PropertiesView.11")
        }); //$NON-NLS-1$ //$NON-NLS-2$

    // Utility measure
    Property m =
        new Property(
            Resources.getMessage("PropertiesView.114"),
            new String[] {metric.getDescription().getName()}); // $NON-NLS-1$

    // Properties of the utility measure
    if (metric.getAggregateFunction() != null) {
      new Property(
          m,
          Resources.getMessage("PropertiesView.149"),
          new String[] {metric.getAggregateFunction().toString()}); // $NON-NLS-1$
    }
    if (metric.isGSFactorSupported()) {
      new Property(
          m,
          Resources.getMessage("PropertiesView.151"),
          new String[] {
            SWTUtil.getPrettyString(metric.getGeneralizationSuppressionFactor())
          }); //$NON-NLS-1$
      new Property(
          m,
          Resources.getMessage("PropertiesView.152"),
          new String[] {SWTUtil.getPrettyString(metric.getGeneralizationFactor())}); // $NON-NLS-1$
      new Property(
          m,
          Resources.getMessage("PropertiesView.153"),
          new String[] {SWTUtil.getPrettyString(metric.getSuppressionFactor())}); // $NON-NLS-1$
    }
    new Property(
        m,
        Resources.getMessage("PropertiesView.155"),
        new String[] {SWTUtil.getPrettyString(metric.isMonotonic())}); // $NON-NLS-1$
    new Property(
        m,
        Resources.getMessage("PropertiesView.156"),
        new String[] {SWTUtil.getPrettyString(metric.isWeighted())}); // $NON-NLS-1$
    new Property(
        m,
        Resources.getMessage("PropertiesView.157"),
        new String[] {SWTUtil.getPrettyString(metric.isPrecomputed())}); // $NON-NLS-1$
    new Property(
        m,
        Resources.getMessage("PropertiesView.158"),
        new String[] {
          SWTUtil.getPrettyString(metric.isAbleToHandleMicroaggregation())
        }); //$NON-NLS-1$

    // Financial configuration
    if (metric instanceof MetricSDNMPublisherPayout) {

      // Obtain for output data
      ARXFinancialConfiguration financial =
          ((MetricSDNMPublisherPayout) metric).getFinancialConfiguration();

      // Obtain for input only. This is a bit ugly.
      if (financial == null) {
        financial = ARXFinancialConfiguration.create();
        financial
            .setAdversaryCost(config.getAdversaryCost())
            .setAdversaryGain(config.getAdversaryGain())
            .setPublisherBenefit(config.getPublisherBenefit())
            .setPublisherLoss(config.getPublisherLoss());
      }

      // Render
      new Property(
          m,
          Resources.getMessage("PropertiesView.135"),
          new String[] {SWTUtil.getPrettyString(financial.getPublisherBenefit())}); // $NON-NLS-1$
      new Property(
          m,
          Resources.getMessage("PropertiesView.136"),
          new String[] {SWTUtil.getPrettyString(financial.getPublisherLoss())}); // $NON-NLS-1$
      new Property(
          m,
          Resources.getMessage("PropertiesView.137"),
          new String[] {SWTUtil.getPrettyString(financial.getAdversaryGain())}); // $NON-NLS-1$
      new Property(
          m,
          Resources.getMessage("PropertiesView.138"),
          new String[] {SWTUtil.getPrettyString(financial.getAdversaryCost())}); // $NON-NLS-1$
      if (((MetricSDNMPublisherPayout) metric).isProsecutorAttackerModel()) {
        new Property(
            m,
            Resources.getMessage("PropertiesView.139"),
            new String[] {Resources.getMessage("PropertiesView.160")}); // $NON-NLS-1$ //$NON-NLS-2$
      }
      if (((MetricSDNMPublisherPayout) metric).isJournalistAttackerModel()) {
        new Property(
            m,
            Resources.getMessage("PropertiesView.139"),
            new String[] {Resources.getMessage("PropertiesView.161")}); // $NON-NLS-1$ //$NON-NLS-2$
      }
    }

    // Attributes
    final Property attributes =
        new Property(
            Resources.getMessage("PropertiesView.12"),
            new String[] {String.valueOf(data.getNumColumns())}); // $NON-NLS-1$

    // Print identifying attributes
    final Property identifying =
        new Property(
            attributes,
            Resources.getMessage("PropertiesView.13"),
            new String[] {
              String.valueOf(definition.getIdentifyingAttributes().size())
            }); //$NON-NLS-1$
    int index = 0;
    for (int i = 0; i < data.getNumColumns(); i++) {
      final String s = data.getAttributeName(i);
      if (definition.getIdentifyingAttributes().contains(s)) {
        final String[] values =
            new String[] {
              "", "", "", "", ""
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        values[0] = s;
        values[1] = definition.getDataType(s).toString();
        new Property(
            identifying,
            Resources.getMessage("PropertiesView.19") + (index++),
            values); //$NON-NLS-1$
      }
    }

    // Print quasi-identifying attributes
    final Property quasiIdentifying =
        new Property(
            attributes,
            Resources.getMessage("PropertiesView.20"),
            new String[] {
              String.valueOf(definition.getQuasiIdentifyingAttributes().size())
            }); //$NON-NLS-1$
    index = 0;
    for (int i = 0; i < data.getNumColumns(); i++) {
      final String s = data.getAttributeName(i);
      if (definition.getQuasiIdentifyingAttributes().contains(s)) {
        final String[] values =
            new String[] {
              "", "", "", "", "", "", "", ""
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
        // //$NON-NLS-7$ //$NON-NLS-8$
        values[0] = s;
        if (definition.getHierarchy(s) != null) {
          DataType<?> type = definition.getDataType(s);
          values[1] = type.getDescription().getLabel();
          if (type.getDescription().hasFormat()
              && ((DataTypeWithFormat) type).getFormat() != null) {
            values[2] = ((DataTypeWithFormat) type).getFormat();
          }

          // Determine height of hierarchy
          int height = 0;
          String[][] hierarchy = definition.getHierarchy(s);
          if (hierarchy != null && hierarchy.length != 0 && hierarchy[0] != null) {
            height = hierarchy[0].length;
          }
          values[3] = String.valueOf(height);
          values[4] = String.valueOf(definition.getMinimumGeneralization(s));
          values[5] = String.valueOf(definition.getMaximumGeneralization(s));
        }
        if (definition.getMicroAggregationFunction(s) != null) {
          values[7] = definition.getMicroAggregationFunction(s).getLabel();
        }
        values[6] = SWTUtil.getPrettyString(config.getAttributeWeight(s));
        new Property(
            quasiIdentifying,
            Resources.getMessage("PropertiesView.26") + (index++),
            values); //$NON-NLS-1$
      }
    }

    // Print sensitive attributes
    final Property sensitive =
        new Property(
            attributes,
            Resources.getMessage("PropertiesView.27"),
            new String[] {
              String.valueOf(definition.getSensitiveAttributes().size())
            }); //$NON-NLS-1$
    index = 0;
    for (int i = 0; i < data.getNumColumns(); i++) {
      final String s = data.getAttributeName(i);
      if (definition.getSensitiveAttributes().contains(s)) {
        final String[] values =
            new String[] {
              "", "", "", "", ""
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        values[0] = s;
        if (config.getHierarchy(s) != null && config.getHierarchy(s).getHierarchy() != null) {
          int height = 0;
          if (config.getHierarchy(s).getHierarchy().length > 0) {
            height = config.getHierarchy(s).getHierarchy()[0].length;
          }
          values[1] = definition.getDataType(s).toString();
          values[2] = String.valueOf(height);
        }
        new Property(
            sensitive,
            Resources.getMessage("PropertiesView.33") + (index++),
            values); //$NON-NLS-1$
      }
    }

    // Print insensitive attributes
    final Property insensitive =
        new Property(
            attributes,
            Resources.getMessage("PropertiesView.34"),
            new String[] {
              String.valueOf(definition.getInsensitiveAttributes().size())
            }); //$NON-NLS-1$

    index = 0;
    for (int i = 0; i < data.getNumColumns(); i++) {
      final String s = data.getAttributeName(i);
      if (definition.getInsensitiveAttributes().contains(s)) {
        final String[] values =
            new String[] {
              "", "", "", "", ""
            }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        values[0] = s;
        values[1] = definition.getDataType(s).toString();
        new Property(
            insensitive,
            Resources.getMessage("PropertiesView.40") + (index++),
            values); //$NON-NLS-1$
      }
    }

    // Refresh and initialize
    refresh();

    // Redraw
    root.setRedraw(true);
  }
Ejemplo n.º 15
0
  /**
   * Reads in preview data
   *
   * <p>This goes through up to {@link ImportWizardModel#PREVIEW_MAX_LINES} lines within the
   * appropriate file and reads them in. It uses {@link ImportAdapter} in combination with {@link
   * ImportConfigurationCSV} to actually read in the data.
   *
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void readPreview() throws IOException {

    /* Reset preview data */
    previewData.clear();

    /* Parameters from the user interface */
    final String location = comboLocation.getText();
    final char delimiter = delimiters[selectedDelimiter];
    final char[] linebreak =
        CSVSyntax.getLinebreakForLabel(CSVSyntax.getAvailableLinebreaks()[selectedLinebreak]);
    final char quote = quotes[selectedQuote];
    final char escape = escapes[selectedEscape];
    final boolean containsHeader = btnContainsHeader.getSelection();
    final Charset charset =
        Charsets.getCharsetForName(Charsets.getNamesOfAvailableCharsets()[selectedCharset]);

    /* Variables needed for processing */
    final CSVDataInput in =
        new CSVDataInput(location, charset, delimiter, quote, escape, linebreak);
    final Iterator<String[]> it = in.iterator();
    final String[] firstLine;
    wizardColumns = new ArrayList<ImportWizardModelColumn>();
    ImportConfigurationCSV config =
        new ImportConfigurationCSV(
            location, charset, delimiter, quote, escape, linebreak, containsHeader);

    /* Check whether there is at least one line in file and retrieve it */
    if (it.hasNext()) {
      firstLine = it.next();
    } else {
      in.close();
      throw new IOException(Resources.getMessage("ImportWizardPageCSV.17")); // $NON-NLS-1$
    }

    /* Iterate over columns and add it to {@link #allColumns} */
    for (int i = 0; i < firstLine.length; i++) {

      ImportColumn column = new ImportColumnCSV(i, DataType.STRING);
      ImportWizardModelColumn wizardColumn = new ImportWizardModelColumn(column);

      wizardColumns.add(wizardColumn);
      config.addColumn(column);
    }

    /* Create adapter to import data with given configuration */
    ImportAdapter importAdapter = ImportAdapter.create(config);

    /* Get up to {ImportData#previewDataMaxLines} lines for previewing */
    int count = 0;
    while (importAdapter.hasNext() && (count <= ImportWizardModel.PREVIEW_MAX_LINES)) {
      previewData.add(importAdapter.next());
      count++;
    }

    in.close();

    /* Remove first entry as it always contains name of columns */
    previewData.remove(0);

    /* Check whether there is actual any data */
    if (previewData.size() == 0) {
      throw new IOException(Resources.getMessage("ImportWizardPageCSV.18")); // $NON-NLS-1$
    }

    /*
     * Show preview in appropriate table
     */

    /* Disable redrawing once redesign is finished */
    tablePreview.setRedraw(false);

    /* Remove all of the old columns */
    while (tablePreview.getColumnCount() > 0) {
      tablePreview.getColumns()[0].dispose();
    }

    /* Add new columns */
    for (ImportWizardModelColumn column : wizardColumns) {

      TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewerPreview, SWT.NONE);
      tableViewerColumn.setLabelProvider(
          new CSVColumnLabelProvider(((ImportColumnCSV) column.getColumn()).getIndex()));

      TableColumn tableColumn = tableViewerColumn.getColumn();
      tableColumn.setWidth(100);

      if (btnContainsHeader.getSelection()) {
        tableColumn.setText(column.getColumn().getAliasName());
        tableColumn.setToolTipText(
            Resources.getMessage("ImportWizardPageCSV.19")
                + ((ImportColumnCSV) column.getColumn()).getIndex()); // $NON-NLS-1$
      }
      ColumnViewerToolTipSupport.enableFor(tableViewerPreview, ToolTip.NO_RECREATE);
    }

    /* Setup preview table */
    tableViewerPreview.setInput(previewData);
    tablePreview.setHeaderVisible(btnContainsHeader.getSelection());
    tablePreview.setVisible(true);
    tablePreview.layout();
    tablePreview.setRedraw(true);
  }
Ejemplo n.º 16
0
/**
 * An about dialog.
 *
 * @author Fabian Prasser
 */
public class DialogAbout extends TitleAreaDialog implements IDialog {

  /** TODO */
  private static final String LICENSE = Resources.getLicenseText();

  /** TODO */
  private static final String ABOUT =
      Resources.getMessage("AboutDialog.16")
          + "\n"
          + //$NON-NLS-1$ //$NON-NLS-2$
          Resources.getMessage("AboutDialog.18")
          + "\n\n"
          + //$NON-NLS-1$ //$NON-NLS-2$
          Resources.getMessage("AboutDialog.21")
          + Resources.getVersion(); // $NON-NLS-1$

  /** TODO */
  private static final String CONTRIBUTORS =
      "Karol Babioch (data import wizard)\n"
          + //$NON-NLS-1$
          "Ledian Xhani (hierarchy editor)\n"
          + //$NON-NLS-1$
          "Ljubomir Dshevlekov (hierarchy editor)\n"
          + //$NON-NLS-1$
          "Michael Schneider (risk analysis)\n"
          + //$NON-NLS-1$
          "Raffael Bild (heuristic search, differential privacy)\n"
          + //$NON-NLS-1$
          "Johanna Eicher (heuristic search)\n"
          + //$NON-NLS-1$
          "Helmut Spengler (heuristic search)\n"
          + //$NON-NLS-1$
          "David Gassmann (HIPAA identifiers)"; //$NON-NLS-1$

  /** TODO */
  private Image image;

  /**
   * Constructor.
   *
   * @param parentShell
   * @param controller
   */
  public DialogAbout(final Shell parentShell, final Controller controller) {
    super(parentShell);
    this.image = controller.getResources().getManagedImage("logo_small.png"); // $NON-NLS-1$
  }

  @Override
  public boolean close() {
    return super.close();
  }

  /**
   * Creates a link.
   *
   * @param parent
   * @param text
   * @param tooltip
   * @param url
   */
  private void createLink(Composite parent, String text, String tooltip, final String url) {
    Link link = new Link(parent, SWT.NONE);
    link.setLayoutData(SWTUtil.createFillHorizontallyGridData());
    link.setText(text);
    link.setToolTipText(tooltip);
    link.setBackground(parent.getBackground());
    link.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            try {
              Program.launch(url);
            } catch (Exception e) {
              /* Ignore*/
            }
          }
        });
  }

  @Override
  protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    newShell.setImages(Resources.getIconSet(newShell.getDisplay()));
  }

  @Override
  protected void createButtonsForButtonBar(final Composite parent) {

    // Create OK Button
    parent.setLayoutData(SWTUtil.createFillGridData());
    final Button okButton =
        createButton(
            parent, Window.OK, Resources.getMessage("AboutDialog.15"), true); // $NON-NLS-1$
    okButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent e) {
            setReturnCode(Window.OK);
            close();
          }
        });
  }

  @Override
  protected Control createContents(Composite parent) {
    Control contents = super.createContents(parent);
    setTitle(Resources.getMessage("AboutDialog.12")); // $NON-NLS-1$
    setMessage(Resources.getMessage("AboutDialog.13"), IMessageProvider.INFORMATION); // $NON-NLS-1$
    if (image != null) setTitleImage(image); // $NON-NLS-1$
    return contents;
  }

  @Override
  protected Control createDialogArea(final Composite parent) {
    parent.setLayout(new GridLayout());

    // Text
    final Label label = new Label(parent, SWT.CENTER | SWT.NONE);
    label.setText(ABOUT);
    label.setLayoutData(SWTUtil.createFillHorizontallyGridData());

    // Folder
    CTabFolder folder = new CTabFolder(parent, SWT.BORDER);
    folder.setSimple(false);
    folder.setLayoutData(SWTUtil.createFillGridData());

    // License
    CTabItem item1 = new CTabItem(folder, SWT.NULL);
    item1.setText("License"); // $NON-NLS-1$
    final Text license = new Text(folder, SWT.NONE | SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    license.setText(LICENSE);
    license.setEditable(false);
    license.setLayoutData(SWTUtil.createFillGridData());
    item1.setControl(license);

    // Contributors
    CTabItem item2 = new CTabItem(folder, SWT.NULL);
    item2.setText("Contributors"); // $NON-NLS-1$
    Composite composite = new Composite(folder, SWT.BORDER);
    composite.setBackground(license.getBackground());
    item2.setControl(composite);
    composite.setLayout(SWTUtil.createGridLayout(1, false));

    final Label contributors = new Label(composite, SWT.NONE);
    contributors.setText(CONTRIBUTORS);
    contributors.setBackground(license.getBackground());
    contributors.setLayoutData(SWTUtil.createFillGridData());

    // Information
    CTabItem item3 = new CTabItem(folder, SWT.NULL);
    item3.setText("Links"); // $NON-NLS-1$
    Composite composite3 = new Composite(folder, SWT.BORDER);
    composite3.setBackground(license.getBackground());
    item3.setControl(composite3);
    composite3.setLayout(SWTUtil.createGridLayout(1, false));
    createLink(
        composite3,
        "Website: <a>arx.deidentifier.org</a>",
        "Website",
        "http://arx.deidentifier.org"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    createLink(
        composite3,
        "Manual: <a>arx.deidentifier.org/anonymization-tool</a>",
        "Manual",
        "http://arx.deidentifier.org/anonymization-tool/"); //$NON-NLS-1$ //$NON-NLS-2$
                                                            // //$NON-NLS-3$
    createLink(
        composite3,
        "API: <a>arx.deidentifier.org/api</a>",
        "API",
        "http://arx.deidentifier.org/api"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    createLink(
        composite3,
        "Downloads: <a>arx.deidentifier.org/downloads</a>",
        "Downloads",
        "http://arx.deidentifier.org/downloads"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    createLink(
        composite3,
        "Github: <a>github.com/arx-deidentifier</a>",
        "Github",
        "https://github.com/arx-deidentifier"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    return parent;
  }

  @Override
  protected boolean isResizable() {
    return false;
  }
}
  /** Resets the chart */
  private void resetChart() {

    if (chart != null) {
      chart.dispose();
    }
    chart = new Chart(root, SWT.NONE);
    chart.setOrientation(SWT.HORIZONTAL);

    // Show/Hide axis
    chart.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(ControlEvent arg0) {
            updateCategories();
          }
        });

    // TODO: Seems to not work on GTK although it did before
    chart
        .getPlotArea()
        .addListener(
            SWT.MouseMove,
            new Listener() {
              @Override
              public void handleEvent(Event event) {
                IAxisSet axisSet = chart.getAxisSet();
                StringBuilder builder = new StringBuilder();
                if (axisSet != null) {
                  IAxis xAxis = axisSet.getXAxis(0);
                  if (xAxis != null) {
                    String[] series = xAxis.getCategorySeries();
                    ISeries[] data = chart.getSeriesSet().getSeries();
                    int x = (int) Math.round(xAxis.getDataCoordinate(event.x));
                    if (x >= 0 && x < series.length) {
                      for (int i = 0; i < data.length; i++) {
                        ISeries yseries = data[i];
                        builder.append(yseries.getId());
                        builder.append("("); // $NON-NLS-1$
                        builder.append(series[x]);
                        builder.append(", "); // $NON-NLS-1$
                        builder.append(yseries.getYSeries()[x]);
                        builder.append(")"); // $NON-NLS-1$
                        if (i < data.length - 1) {
                          builder.append(", "); // $NON-NLS-1$
                        }
                      }
                    }
                  }
                }
                if (builder.length() != 0) {
                  chart.getPlotArea().setToolTipText(builder.toString());
                } else {
                  chart.getPlotArea().setToolTipText(null);
                }
              }
            });

    // Update font
    FontData[] fd = chart.getFont().getFontData();
    fd[0].setHeight(8);
    final Font font = new Font(chart.getDisplay(), fd[0]);
    chart.setFont(font);
    chart.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent arg0) {
            if (font != null && !font.isDisposed()) {
              font.dispose();
            }
          }
        });

    // Update title
    ITitle graphTitle = chart.getTitle();
    graphTitle.setText(""); // $NON-NLS-1$
    graphTitle.setFont(chart.getFont());

    // Set colors
    chart.setBackground(root.getBackground());
    chart.setForeground(root.getForeground());

    // OSX workaround
    if (System.getProperty("os.name").toLowerCase().contains("mac")) { // $NON-NLS-1$ //$NON-NLS-2$
      int r = chart.getBackground().getRed() - 13;
      int g = chart.getBackground().getGreen() - 13;
      int b = chart.getBackground().getBlue() - 13;
      r = r > 0 ? r : 0;
      r = g > 0 ? g : 0;
      r = b > 0 ? b : 0;
      final Color background = new Color(chart.getDisplay(), r, g, b);
      chart.setBackground(background);
      chart.addDisposeListener(
          new DisposeListener() {
            public void widgetDisposed(DisposeEvent arg0) {
              if (background != null && !background.isDisposed()) {
                background.dispose();
              }
            }
          });
    }

    // Initialize axes
    IAxisSet axisSet = chart.getAxisSet();
    IAxis yAxis = axisSet.getYAxis(0);
    IAxis xAxis = axisSet.getXAxis(0);
    ITitle xAxisTitle = xAxis.getTitle();
    xAxisTitle.setText(""); // $NON-NLS-1$
    xAxis.getTitle().setFont(chart.getFont());
    yAxis.getTitle().setFont(chart.getFont());
    xAxis.getTick().setFont(chart.getFont());
    yAxis.getTick().setFont(chart.getFont());
    xAxis.getTick().setForeground(chart.getForeground());
    yAxis.getTick().setForeground(chart.getForeground());
    xAxis.getTitle().setForeground(chart.getForeground());
    yAxis.getTitle().setForeground(chart.getForeground());

    // Initialize y-axis
    ITitle yAxisTitle = yAxis.getTitle();
    yAxisTitle.setText(Resources.getMessage("ViewRisksPlotUniquenessEstimates.0")); // $NON-NLS-1$
    chart.setEnabled(false);
    updateCategories();
  }
Ejemplo n.º 18
0
 @Override
 protected void configureShell(Shell newShell) {
   super.configureShell(newShell);
   newShell.setImages(Resources.getIconSet(newShell.getDisplay()));
 }
Ejemplo n.º 19
0
 /**
  * Creates a new instance of this page and sets its title and description.
  *
  * @param wizardImport Reference to wizard containing this page
  */
 public ImportWizardPageSource(ImportWizard wizardImport) {
   super("WizardImportSourcePage"); // $NON-NLS-1$
   setTitle(Resources.getMessage("ImportWizardPageSource.1")); // $NON-NLS-1$
   setDescription(Resources.getMessage("ImportWizardPageSource.2")); // $NON-NLS-1$
   this.wizardImport = wizardImport;
 }
Ejemplo n.º 20
0
Archivo: Main.java Proyecto: p2y/arx
  /**
   * Main entry point.
   *
   * @param args
   */
  public static void main(Display display, final String[] args) {

    try {
      // Make fall-back toolkit look like the native UI
      if (!isUnix()) { // See: https://bugs.eclipse.org/bugs/show_bug.cgi?id=341799
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
    } catch (ClassNotFoundException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
      // Ignore
    }

    try {

      // Display
      if (display == null) {
        display = new Display();
      }

      // Monitor
      Monitor monitor = getMonitor(display);

      // Splash
      splash = new MainSplash(display, monitor);
      splash.show();

      // Create main window
      main = new MainWindow(display, monitor);

      // Handler for loading a project
      if (args.length > 0 && args[0].endsWith(".deid")) { // $NON-NLS-1$
        main.onShow(
            new Runnable() {
              public void run() {
                load(main, args[0]);
              }
            });
      }

      // Show window
      main.show();

      new Update(main.getShell());

      // Main event loop
      while (!main.isDisposed()) {
        try {

          // Event handling
          if (!display.readAndDispatch()) {
            display.sleep();
          }
        } catch (final Exception e) {

          // Error handling
          main.showErrorDialog(
              Resources.getMessage("MainWindow.9") + Resources.getMessage("MainWindow.10"),
              e); //$NON-NLS-1$ //$NON-NLS-2$
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw);
          e.printStackTrace(pw);
          main.getController().getResources().getLogger().info(sw.toString());
        }
      }

      // Dispose display
      if (!display.isDisposed()) {
        display.dispose();
      }
    } catch (Throwable e) {

      // Error handling outside of SWT
      if (splash != null) splash.hide();
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      e.printStackTrace(pw);
      final String trace = sw.toString();

      // Show message
      JOptionPane.showMessageDialog(
          null, trace, "Unexpected error", JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$
      System.exit(1);
    }
  }
Ejemplo n.º 21
0
  @Override
  public void update(final ModelEvent event) {

    super.update(event);

    if (event.part == ModelPart.SELECTED_NODE) {
      if (model.getSelectedNode() != null) {
        toolbar.setRedraw(false);
        labelSelected.setText(
            Resources.getMessage("MainToolBar.3")
                + //$NON-NLS-1$
                Arrays.toString(model.getSelectedNode().getTransformation()));
        labelSelected.pack();
        layout();
        toolbar.setRedraw(true);
      }
    } else if (event.part == ModelPart.OUTPUT) {
      if (model.getOutputNode() != null) {

        // Update tool tip
        SearchSpaceStatistics stats = new SearchSpaceStatistics(model.getResult());
        setToolTip(stats);

        // Update labels
        toolbar.setRedraw(false);
        labelTransformations.setText(
            Resources.getMessage("MainToolBar.6")
                + //$NON-NLS-1$
                SWTUtil.getPrettyString(stats.numTransformationsInSearchSpace));
        labelTransformations.pack();

        labelApplied.setText(
            Resources.getMessage("MainToolBar.4")
                + //$NON-NLS-1$
                Arrays.toString(model.getOutputNode().getTransformation()));
        labelApplied.pack();

        layout();

        toolbar.setRedraw(true);
      } else {
        reset();
      }
    } else if (event.part == ModelPart.RESULT) {
      if (model.getResult() != null) {

        // Update tool tip
        SearchSpaceStatistics stats = new SearchSpaceStatistics(model.getResult());
        setToolTip(stats);

        // Update labels
        toolbar.setRedraw(false);
        labelTransformations.setText(
            Resources.getMessage("MainToolBar.6")
                + //$NON-NLS-1$
                SWTUtil.getPrettyString(stats.numTransformationsInSearchSpace));
        labelTransformations.pack();

        labelSelected.setText(Resources.getMessage("MainToolBar.7")); // $NON-NLS-1$
        labelSelected.pack();

        labelApplied.setText(Resources.getMessage("MainToolBar.8")); // $NON-NLS-1$
        labelApplied.pack();

        layout();

        toolbar.setRedraw(true);
      }
    } else if (event.part == ModelPart.SELECTED_ATTRIBUTE) {
      String attribute = (String) event.data;

      // Update label
      toolbar.setRedraw(false);
      labelAttribute.setText(
          Resources.getMessage("MainToolBar.50") + trim(attribute)); // $NON-NLS-1$
      labelAttribute.pack();
      layout();
      toolbar.setRedraw(true);
    } else if (event.part == ModelPart.MODEL) {
      model = (Model) event.data;
    }
  }
Ejemplo n.º 22
0
  /**
   * Creates a new data view.
   *
   * @param parent
   * @param controller
   * @param title
   */
  public ViewData(final Composite parent, final Controller controller, final String title) {

    // Register
    controller.addListener(ModelPart.ATTRIBUTE_TYPE, this);
    controller.addListener(ModelPart.SELECTED_ATTRIBUTE, this);
    controller.addListener(ModelPart.MODEL, this);
    controller.addListener(ModelPart.OUTPUT, this);
    controller.addListener(ModelPart.SELECTED_VIEW_CONFIG, this);
    controller.addListener(ModelPart.INPUT, this);

    // Store
    this.controller = controller;

    // Load images
    IMAGE_INSENSITIVE =
        controller.getResources().getManagedImage("bullet_green.png"); // $NON-NLS-1$
    IMAGE_SENSITIVE = controller.getResources().getManagedImage("bullet_purple.png"); // $NON-NLS-1$
    IMAGE_QUASI_IDENTIFYING =
        controller.getResources().getManagedImage("bullet_yellow.png"); // $NON-NLS-1$
    IMAGE_IDENTIFYING = controller.getResources().getManagedImage("bullet_red.png"); // $NON-NLS-1$
    IMAGE_ASCENDING =
        controller.getResources().getManagedImage("sort_ascending.png"); // $NON-NLS-1$
    IMAGE_DESCENDING =
        controller.getResources().getManagedImage("sort_descending.png"); // $NON-NLS-1$

    // Create title bar
    ComponentTitledFolderButton bar = new ComponentTitledFolderButton("id-140"); // $NON-NLS-1$
    bar.add(
        Resources.getMessage("DataView.1"), // $NON-NLS-1$
        IMAGE_ASCENDING,
        new Runnable() {
          @Override
          public void run() {
            model.getViewConfig().setSortOrder(true);
            actionSort();
          }
        });
    bar.add(
        Resources.getMessage("DataView.4"), // $NON-NLS-1$
        IMAGE_DESCENDING,
        new Runnable() {
          @Override
          public void run() {
            model.getViewConfig().setSortOrder(false);
            actionSort();
          }
        });
    bar.add(
        Resources.getMessage("DataView.2"), // $NON-NLS-1$
        controller.getResources().getManagedImage("sort_groups.png"), // $NON-NLS-1$
        new Runnable() {
          @Override
          public void run() {
            controller.actionDataShowGroups();
          }
        });
    bar.add(
        Resources.getMessage("DataView.3"), // $NON-NLS-1$
        controller.getResources().getManagedImage("sort_subset.png"), // $NON-NLS-1$
        true,
        new Runnable() {
          @Override
          public void run() {
            controller.actionDataToggleSubset();
          }
        });

    // Build border
    ComponentTitledFolder folder = new ComponentTitledFolder(parent, controller, bar, null);
    folder.setLayoutData(SWTUtil.createFillGridData());
    Composite c = folder.createItem(title, null);
    folder.setSelection(0);
    GridLayout l = new GridLayout();
    l.numColumns = 1;
    c.setLayout(l);

    // Build table
    table = new ComponentDataTable(controller, c);
    table.addSelectionLayerListener(
        new ILayerListener() {
          @Override
          public void handleLayerEvent(ILayerEvent arg0) {
            if (arg0 instanceof CellSelectionEvent) {
              actionCellSelected((CellSelectionEvent) arg0);
            } else if (arg0 instanceof ColumnSelectionEvent) {
              actionColumnSelected((ColumnSelectionEvent) arg0);
            }
          }
        });

    // Build buttons
    this.groupsButton = folder.getButtonItem(Resources.getMessage("DataView.2")); // $NON-NLS-1$
    this.groupsButton.setEnabled(false);
    this.subsetButton = folder.getButtonItem(Resources.getMessage("DataView.3")); // $NON-NLS-1$
    this.subsetButton.setEnabled(false);
    this.ascendingButton = folder.getButtonItem(Resources.getMessage("DataView.1")); // $NON-NLS-1$
    this.ascendingButton.setEnabled(false);
    this.descendingButton = folder.getButtonItem(Resources.getMessage("DataView.4")); // $NON-NLS-1$
    this.descendingButton.setEnabled(false);
  }
Ejemplo n.º 23
0
  /**
   * Creates the design of this page
   *
   * <p>This adds all the controls to the page along with their listeners.
   *
   * @param parent the parent
   * @note {@link #tablePreview} is not visible until a file is loaded.
   */
  public void createControl(Composite parent) {

    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(3, false));

    /* Location label */
    lblLocation = new Label(container, SWT.NONE);
    lblLocation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblLocation.setText(Resources.getMessage("ImportWizardPageCSV.7")); // $NON-NLS-1$

    /* Combo box for selection of file */
    comboLocation = new Combo(container, SWT.READ_ONLY);
    comboLocation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboLocation.addSelectionListener(
        new SelectionAdapter() {
          /** Resets {@link customSeparator} and evaluates page */
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            /* Make widgets visible */
            lblDelimiter.setVisible(true);
            comboDelimiter.setVisible(true);
            lblQuote.setVisible(true);
            comboQuote.setVisible(true);
            lblLinebreak.setVisible(true);
            comboLinebreak.setVisible(true);
            lblEscape.setVisible(true);
            lblCharset.setVisible(true);
            comboCharset.setVisible(true);
            comboEscape.setVisible(true);
            btnContainsHeader.setVisible(true);
            customDelimiter = false;
            customLinebreak = false;
            evaluatePage();
          }
        });

    /* Button to open file selection dialog */
    btnChoose = new Button(container, SWT.NONE);
    btnChoose.setText(Resources.getMessage("ImportWizardPageCSV.8")); // $NON-NLS-1$
    btnChoose.addSelectionListener(
        new SelectionAdapter() {

          /**
           * Opens a file selection dialog for CSV files
           *
           * <p>If a valid CSV file was selected, it is added to {@link #comboLocation} when it
           * wasn't already there. It is then preselected within {@link #comboLocation} and the page
           * is evaluated {@see #evaluatePage}.
           */
          @Override
          public void widgetSelected(SelectionEvent arg0) {

            /* Open file dialog */
            final String path =
                wizardImport
                    .getController()
                    .actionShowOpenFileDialog(getShell(), "*.csv"); // $NON-NLS-1$
            if (path == null) {
              return;
            }

            /* Check whether path was already added */
            if (comboLocation.indexOf(path) == -1) {
              comboLocation.add(path, 0);
            }

            /* Select path and notify comboLocation about change */
            comboLocation.select(comboLocation.indexOf(path));
            comboLocation.notifyListeners(SWT.Selection, null);
          }
        });

    /* Delimiter label */
    lblCharset = new Label(container, SWT.NONE);
    lblCharset.setVisible(false);
    lblCharset.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblCharset.setText(Resources.getMessage("ImportWizardPageCSV.20")); // $NON-NLS-1$

    /* Delimiter combobox */
    comboCharset = new Combo(container, SWT.READ_ONLY);
    comboCharset.setVisible(false);

    /* Add labels */
    int index = 0;
    for (final String s : Charsets.getNamesOfAvailableCharsets()) {
      comboCharset.add(s);
      if (s.equals(Charsets.getNameOfDefaultCharset())) {
        selectedCharset = index;
      }
      index++;
    }

    comboCharset.select(selectedCharset);
    comboCharset.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboCharset.addSelectionListener(
        new SelectionAdapter() {

          /** Set selection index and customDelimiter and (re-)evaluates page */
          @Override
          public void widgetSelected(final SelectionEvent arg0) {
            selectedCharset = comboCharset.getSelectionIndex();
            evaluatePage();
          }
        });

    /* Place holder */
    new Label(container, SWT.NONE);

    /* Delimiter label */
    lblDelimiter = new Label(container, SWT.NONE);
    lblDelimiter.setVisible(false);
    lblDelimiter.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblDelimiter.setText(Resources.getMessage("ImportWizardPageCSV.10")); // $NON-NLS-1$

    /* Delimiter combobox */
    comboDelimiter = new Combo(container, SWT.READ_ONLY);
    comboDelimiter.setVisible(false);

    /* Add labels */
    for (final String s : labels) {
      comboDelimiter.add(s);
    }

    comboDelimiter.select(selectedDelimiter);
    comboDelimiter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboDelimiter.addSelectionListener(
        new SelectionAdapter() {

          /** Set selection index and customDelimiter and (re-)evaluates page */
          @Override
          public void widgetSelected(final SelectionEvent arg0) {
            selectedDelimiter = comboDelimiter.getSelectionIndex();
            customDelimiter = true;
            evaluatePage();
          }
        });

    /* Place holder */
    new Label(container, SWT.NONE);

    /* Quote label */
    lblQuote = new Label(container, SWT.NONE);
    lblQuote.setVisible(false);
    lblQuote.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblQuote.setText(Resources.getMessage("ImportWizardPageCSV.11")); // $NON-NLS-1$

    /* Quote combobox */
    comboQuote = new Combo(container, SWT.READ_ONLY);
    comboQuote.setVisible(false);

    /* Add labels */
    for (final char c : quotes) {
      comboQuote.add(String.valueOf(c));
    }

    comboQuote.select(selectedQuote);
    comboQuote.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboQuote.addSelectionListener(
        new SelectionAdapter() {

          /** Set selection index and custom quote and (re-)evaluates page */
          @Override
          public void widgetSelected(final SelectionEvent arg0) {
            selectedQuote = comboQuote.getSelectionIndex();
            evaluatePage();
          }
        });

    /* Place holder */
    new Label(container, SWT.NONE);

    /* Escape label */
    lblEscape = new Label(container, SWT.NONE);
    lblEscape.setVisible(false);
    lblEscape.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblEscape.setText(Resources.getMessage("ImportWizardPageCSV.12")); // $NON-NLS-1$

    /* Escape combobox */
    comboEscape = new Combo(container, SWT.READ_ONLY);
    comboEscape.setVisible(false);

    /* Add labels */
    for (final char c : escapes) {
      comboEscape.add(String.valueOf(c));
    }

    comboEscape.select(selectedEscape);
    comboEscape.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboEscape.addSelectionListener(
        new SelectionAdapter() {

          /** Set selection index and custom escape and (re-)evaluates page */
          @Override
          public void widgetSelected(final SelectionEvent arg0) {
            selectedEscape = comboEscape.getSelectionIndex();
            evaluatePage();
          }
        });

    /* Place holder */
    new Label(container, SWT.NONE);

    /* Line break label */
    lblLinebreak = new Label(container, SWT.NONE);
    lblLinebreak.setVisible(false);
    lblLinebreak.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblLinebreak.setText(Resources.getMessage("ImportWizardPageCSV.13")); // $NON-NLS-1$

    /* Line break combobox */
    comboLinebreak = new Combo(container, SWT.READ_ONLY);
    comboLinebreak.setVisible(false);

    /* Add labels */
    for (final String c : CSVSyntax.getAvailableLinebreaks()) {
      comboLinebreak.add(String.valueOf(c));
    }

    comboLinebreak.select(selectedLinebreak);
    comboLinebreak.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    comboLinebreak.addSelectionListener(
        new SelectionAdapter() {

          /** Set selection index and custom line break and (re-)evaluates page */
          @Override
          public void widgetSelected(final SelectionEvent arg0) {
            selectedLinebreak = comboLinebreak.getSelectionIndex();
            customLinebreak = true;
            evaluatePage();
          }
        });

    /* Place holders */
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);

    /* Contains header button */
    btnContainsHeader = new Button(container, SWT.CHECK);
    btnContainsHeader.setVisible(false);
    btnContainsHeader.setText(Resources.getMessage("ImportWizardPageCSV.14")); // $NON-NLS-1$
    btnContainsHeader.setSelection(true);
    btnContainsHeader.addSelectionListener(
        new SelectionAdapter() {

          /** (Re-)Evaluate page */
          @Override
          public void widgetSelected(SelectionEvent arg0) {
            evaluatePage();
          }
        });

    /* Place holder */
    new Label(container, SWT.NONE);

    /* Place holders */
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);

    /* Preview table viewer */
    tableViewerPreview = SWTUtil.createTableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);
    tableViewerPreview.setContentProvider(new ArrayContentProvider());

    /* Actual table for {@link #tableViewerPreview} */
    tablePreview = tableViewerPreview.getTable();
    GridData gd_tablePreview = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gd_tablePreview.heightHint = 150;
    tablePreview.setLayoutData(gd_tablePreview);
    tablePreview.setLinesVisible(true);
    tablePreview.setVisible(false);

    /* Set page to incomplete by default */
    setPageComplete(false);
  }