Skip to content

Commit

Permalink
Export wizard.
Browse files Browse the repository at this point in the history
  • Loading branch information
dma committed Jun 29, 2016
1 parent 7c7561f commit 9533ff1
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 2 deletions.
3 changes: 2 additions & 1 deletion platform/com.subgraph.vega.ui.util/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml
plugin.xml,\
icons/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;

import com.subgraph.vega.api.model.IModel;

/**
* The activator class controls the plug-in life cycle
Expand All @@ -13,7 +16,8 @@ public class Activator extends AbstractUIPlugin {

// The shared instance
private static Activator plugin;

private ServiceTracker<IModel, IModel> modelTracker;

/**
* The constructor
*/
Expand All @@ -27,6 +31,8 @@ public Activator() {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
modelTracker = new ServiceTracker<IModel, IModel>(context, IModel.class.getName(), null);
modelTracker.open();
}

/*
Expand All @@ -47,4 +53,7 @@ public static Activator getDefault() {
return plugin;
}

public IModel getModel() {
return modelTracker.getService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.subgraph.vega.ui.util.export;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.wizard.Wizard;

import com.subgraph.vega.api.model.alerts.IScanAlert;
import com.subgraph.vega.api.model.alerts.IScanInstance;
import com.subgraph.vega.export.AlertExporter;

public class AlertExportWizard extends Wizard {

protected ExportWizardPageOne one;
protected ExportWizardPageTwo two;
protected ExportWizardPageThree three;
private IScanInstance scanInstance = null;

public AlertExportWizard(IScanInstance s) {
super();
scanInstance = s;
}

public AlertExportWizard() {
super();
}

@Override
public void addPages() {
one = new ExportWizardPageOne();
two = new ExportWizardPageTwo(scanInstance);
three = new ExportWizardPageThree();
addPage(one);
addPage(two);
addPage(three);

}

@Override
public boolean performFinish() {
// TODO Auto-generated method stub


List<IScanAlert> alerts;
alerts = two.allAlertsFromTree();
System.out.println(alerts.size());

AlertExporter exporter = new AlertExporter();
exporter.exportAlertsbyList(alerts);

return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.subgraph.vega.ui.util.export;



import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;

public class ExportWizardPageOne extends WizardPage {


private Composite container;
private Group radioGroup;
private String choice = "HTML";

protected ExportWizardPageOne() {
super("Output format");
setTitle("Output format");
setDescription("HTML or XML output format.");

}

@Override
public void createControl(Composite parent) {

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

GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
container.setLayoutData(gd);

GridLayout layout = new GridLayout();

container.setLayout(layout);
layout.numColumns = 1;

/*Label l = new Label(container, SWT.NONE);
l.setText("Select XML or HTML output.");*/


radioGroup = new Group(container, SWT.SHADOW_IN);
radioGroup.setText("Select XML or HTML output.");
gd.grabExcessHorizontalSpace = true;
radioGroup.setLayoutData(gd);

radioGroup.setLayout(new RowLayout(SWT.VERTICAL));
Button htmlButton = new Button(radioGroup, SWT.RADIO);
Button xmlButton = new Button(radioGroup, SWT.RADIO);
xmlButton.setText("XML");
htmlButton.setText("HTML");
htmlButton.setSelection(true);
xmlButton.addSelectionListener(new SelectionAdapter() {

public void widgetSelected(SelectionEvent e) {
choice = xmlButton.getText();
}
});

htmlButton.addSelectionListener(new SelectionAdapter() {

public void widgetSelected(SelectionEvent e) {
choice = xmlButton.getText();
}
});

setControl(container);

}

protected String getChoice() {
return this.choice;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.subgraph.vega.ui.util.export;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class ExportWizardPageThree extends WizardPage {

protected FileDialog dialog;
protected Text textField;
protected Composite container;
private String saveFilename = null;
private String filename = null;

final static int VISIBLE_PATH_LENGTH = 255;

protected ExportWizardPageThree() {
super("Output destination");



setTitle("Destination for report output.");

}

@Override
public void createControl(Composite parent) {

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

GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 2;

Label label = new Label(container, SWT.NONE);
label.setText("Choose file:");
textField = new Text(container, SWT.READ_ONLY | SWT.FILL);
textField.setSize(VISIBLE_PATH_LENGTH, textField.getSize().y);
Button button = new Button(container, SWT.NONE);
button.setText("Open");

GridData buttonGridData = new GridData();
buttonGridData.horizontalSpan = 2;
buttonGridData.horizontalAlignment = SWT.END;
button.setLayoutData(buttonGridData);

GridData textFieldGridData = new GridData();
textFieldGridData.widthHint = 300;
textField.setLayoutData(textFieldGridData);

button.addSelectionListener (new SelectionListener() {

@Override
public void widgetSelected(SelectionEvent e) {
doFileDialog(parent.getShell());
}

@Override
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub

}});

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
filename = "Vega-report-"+dateFormat.format(new Date());

IWizardPage pageOne = getPreviousPage().getPreviousPage();
String ext = ((ExportWizardPageOne) pageOne).getChoice();

if (ext.equals("HTML")) {
filename += ".html";
} else if (ext.equals("XML")){
filename += ".xml";
}

setPageComplete(false);
setControl(container);
}

private void doFileDialog(Shell shell) {
dialog = new FileDialog(shell, SWT.SAVE);
dialog.setText("Choose an output file");

dialog.setFileName(filename);
saveFilename = dialog.open();
if (saveFilename != null) {
textField.setText(saveFilename);
setPageComplete(true);
}
}

String getSaveFilename() {
return saveFilename;
}
}
Loading

0 comments on commit 9533ff1

Please sign in to comment.