use of org.eclipse.swt.custom.SashForm in project dbeaver by serge-rider.
the class PostgreBackupWizardPageObjects method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 1);
Group objectsGroup = UIUtils.createControlGroup(composite, "Objects", 1, GridData.FILL_HORIZONTAL, 0);
objectsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
SashForm sash = new CustomSashForm(objectsGroup, SWT.VERTICAL);
sash.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite catPanel = UIUtils.createPlaceholder(sash, 1);
catPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
schemasTable = new Table(catPanel, SWT.BORDER | SWT.CHECK);
schemasTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
PostgreSchema catalog = (PostgreSchema) item.getData();
if (event.detail == SWT.CHECK) {
schemasTable.select(schemasTable.indexOf(item));
checkedObjects.remove(catalog);
}
loadTables(catalog);
updateState();
}
});
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 50;
schemasTable.setLayoutData(gd);
Composite buttonsPanel = UIUtils.createPlaceholder(catPanel, 3, 5);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(buttonsPanel, SWT.NONE).setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
createCheckButtons(buttonsPanel, schemasTable);
}
final Button exportViewsCheck;
{
Composite tablesPanel = UIUtils.createPlaceholder(sash, 1);
tablesPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
tablesTable = new Table(tablesPanel, SWT.BORDER | SWT.CHECK);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 50;
tablesTable.setLayoutData(gd);
tablesTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.CHECK) {
updateCheckedTables();
updateState();
}
}
});
Composite buttonsPanel = UIUtils.createPlaceholder(tablesPanel, 3, 5);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
exportViewsCheck = UIUtils.createCheckbox(buttonsPanel, "Show views", false);
exportViewsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
wizard.showViews = exportViewsCheck.getSelection();
loadTables(null);
}
});
exportViewsCheck.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
createCheckButtons(buttonsPanel, tablesTable);
}
dataSource = null;
Set<PostgreSchema> activeCatalogs = new LinkedHashSet<>();
for (DBSObject object : wizard.getDatabaseObjects()) {
if (object instanceof PostgreSchema) {
activeCatalogs.add((PostgreSchema) object);
dataSource = ((PostgreSchema) object).getDataSource();
} else if (object instanceof PostgreTableBase) {
PostgreSchema catalog = ((PostgreTableBase) object).getContainer();
dataSource = catalog.getDataSource();
activeCatalogs.add(catalog);
Set<PostgreTableBase> tables = checkedObjects.get(catalog);
if (tables == null) {
tables = new HashSet<>();
checkedObjects.put(catalog, tables);
}
tables.add((PostgreTableBase) object);
if (((PostgreTableBase) object).isView()) {
wizard.showViews = true;
exportViewsCheck.setSelection(true);
}
} else if (object.getDataSource() instanceof PostgreDataSource) {
dataSource = (PostgreDataSource) object.getDataSource();
}
}
if (dataSource != null) {
boolean tablesLoaded = false;
try {
for (PostgreSchema schema : dataSource.getDefaultInstance().getSchemas(VoidProgressMonitor.INSTANCE)) {
if (schema.isSystem() || schema.isUtility()) {
continue;
}
TableItem item = new TableItem(schemasTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(DBIcon.TREE_DATABASE));
item.setText(0, schema.getName());
item.setData(schema);
if (activeCatalogs.contains(schema)) {
item.setChecked(true);
schemasTable.select(schemasTable.indexOf(item));
if (!tablesLoaded) {
loadTables(schema);
tablesLoaded = true;
}
}
}
} catch (DBException e) {
log.error(e);
}
}
updateState();
setControl(composite);
}
use of org.eclipse.swt.custom.SashForm in project dbeaver by serge-rider.
the class MultiPageWizardDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
wizard.addPages();
wizardSash = new SashForm(composite, SWT.HORIZONTAL);
wizardSash.setLayoutData(new GridData(GridData.FILL_BOTH));
pagesTree = new Tree(wizardSash, SWT.SINGLE);
pagesTree.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite pageContainer = UIUtils.createPlaceholder(wizardSash, 2);
// Vertical separator
new Label(pageContainer, SWT.SEPARATOR | SWT.VERTICAL).setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, true));
pageArea = UIUtils.createPlaceholder(pageContainer, 1);
GridData gd = new GridData(GridData.FILL_BOTH);
pageArea.setLayoutData(gd);
pageArea.setLayout(new GridLayout(1, true));
wizardSash.setWeights(new int[] { 300, 700 });
Point maxSize = new Point(0, 0);
IWizardPage[] pages = wizard.getPages();
for (IWizardPage page : pages) {
addPage(null, page, maxSize);
}
gd = (GridData) pageArea.getLayoutData();
gd.widthHint = 500;
gd.heightHint = 400;
pagesTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changePage();
}
});
// Select first page
pagesTree.select(pagesTree.getItem(0));
changePage();
// Set title and image from first page
IDialogPage firstPage = (IDialogPage) pagesTree.getItem(0).getData();
setTitle(firstPage.getTitle());
setTitleImage(firstPage.getImage());
setMessage(firstPage.getMessage());
// Horizontal separator
new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Progress monitor
monitorPart = new ProgressMonitorPart(composite, null, true) {
@Override
public void setCanceled(boolean b) {
super.setCanceled(b);
if (b) {
cancelCurrentOperation();
}
}
};
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.grabExcessHorizontalSpace = true;
gd.horizontalIndent = 20;
gd.verticalIndent = 0;
monitorPart.setLayoutData(gd);
monitorPart.setVisible(false);
return composite;
}
use of org.eclipse.swt.custom.SashForm in project otertool by wuntee.
the class Gui method createContents.
/**
* Create contents of the window.
*/
protected void createContents() {
shlOterTool = new Shell();
shlOterTool.setImage(SWTResourceManager.getImage(Gui.class, OterStatics.ICON_APP));
shlOterTool.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
try {
logcatController.stop();
} catch (Exception e) {
// Do nothing
}
}
});
shlOterTool.setMinimumSize(new Point(550, 250));
shlOterTool.setSize(1000, 600);
shlOterTool.setText("Otertool");
shlOterTool.setLayout(new FormLayout());
Menu menu = new Menu(shlOterTool, SWT.BAR);
shlOterTool.setMenuBar(menu);
MenuItem mntmFile = new MenuItem(menu, SWT.CASCADE);
mntmFile.setText("File");
Menu menu_1 = new Menu(mntmFile);
mntmFile.setMenu(menu_1);
MenuItem mntmConfigure = new MenuItem(menu_1, SWT.NONE);
mntmConfigure.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
Object ret = new ConfigurationDialog(shlOterTool).open();
}
});
mntmConfigure.setText("Configure");
new MenuItem(menu_1, SWT.SEPARATOR);
MenuItem mntmExit = new MenuItem(menu_1, SWT.NONE);
mntmExit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
System.exit(0);
}
});
mntmExit.setText("Exit");
MenuItem mntmLogcat = new MenuItem(menu, SWT.CASCADE);
mntmLogcat.setText("LogCat");
Menu menu_2 = new Menu(mntmLogcat);
mntmLogcat.setMenu(menu_2);
MenuItem mntmStart = new MenuItem(menu_2, SWT.NONE);
mntmStart.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
logcatController.start();
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not start: " + e.getMessage());
logger.error("Could not start logcat:", e);
}
}
});
mntmStart.setText("Start");
MenuItem mntmStop = new MenuItem(menu_2, SWT.NONE);
mntmStop.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.stop();
}
});
mntmStop.setText("Stop");
new MenuItem(menu_2, SWT.SEPARATOR);
MenuItem mntmClear = new MenuItem(menu_2, SWT.NONE);
mntmClear.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatTable.removeAll();
}
});
mntmClear.setText("Clear");
MenuItem mntmFsdiff = new MenuItem(menu, SWT.CASCADE);
mntmFsdiff.setText("FsDiff");
Menu menu_3 = new Menu(mntmFsdiff);
mntmFsdiff.setMenu(menu_3);
MenuItem mntmScanFirst = new MenuItem(menu_3, SWT.NONE);
mntmScanFirst.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
fsDiffController.scanFirst();
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not scan: " + e.getMessage());
logger.error("Could not scan:", e);
}
}
});
mntmScanFirst.setText("Scan First");
MenuItem mntmScanSecond = new MenuItem(menu_3, SWT.NONE);
mntmScanSecond.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
fsDiffController.scanSecond();
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not scan: " + e.getMessage());
logger.error("Could not scan:", e);
}
}
});
mntmScanSecond.setText("Scan Second");
MenuItem mntmGenerateDifferences = new MenuItem(menu_3, SWT.NONE);
mntmGenerateDifferences.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
fsDiffController.generateDifferences();
}
});
mntmGenerateDifferences.setText("Generate Differences");
new MenuItem(menu_3, SWT.SEPARATOR);
MenuItem mntmClear_1 = new MenuItem(menu_3, SWT.NONE);
mntmClear_1.setText("Clear");
MenuItem mntmApktool = new MenuItem(menu, SWT.CASCADE);
mntmApktool.setText("Smali");
Menu menu_4 = new Menu(mntmApktool);
mntmApktool.setMenu(menu_4);
MenuItem mntmLoadFile = new MenuItem(menu_4, SWT.NONE);
mntmLoadFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
String file = GuiWorkshop.selectFile(shlOterTool, new String[] { "*.apk" });
if (file != null) {
smaliController.loadApk(new File(file));
}
}
});
mntmLoadFile.setText("Load APK");
MenuItem mntmLoadApkDevice = new MenuItem(menu_4, SWT.NONE);
mntmLoadApkDevice.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
PackageBean apkBean = new LoadApkFromDeviceDialog(shlOterTool).open();
if (apkBean != null) {
smaliController.loadApkFromDevice(apkBean);
}
}
});
mntmLoadApkDevice.setText("Load APK From Device");
MenuItem mntmBuild = new MenuItem(menu_4, SWT.NONE);
mntmBuild.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (smaliController.unsavedFilesOpen() == true) {
int save = GuiWorkshop.yesNoDialog(getShell(), "Really build?", "You have unsaved smali files; if you do not save them, they will not be applied to the new APK. Are you sure you want to rebuild the APK without saving?");
if (save == SWT.NO) {
return;
}
}
BuildAndSignApkBean bean = new BuildAndSignApkDialog(getShell()).open();
if (bean != null && bean.getApkFilename() != null) {
if (bean.isSign()) {
if (bean.getApkFilename() != null && bean.getCertAlias() != null && bean.getCertFilename() != null && bean.getPassword() != null) {
setStatus("Building and signing APK to: " + bean.getApkFilename());
smaliController.rebuildAndSignApk(bean);
}
} else {
smaliController.rebuildApk(bean.getApkFilename());
}
}
}
});
mntmBuild.setText("Build APK...");
MenuItem mntmJavaToSmali = new MenuItem(menu, SWT.CASCADE);
mntmJavaToSmali.setText("Java to Smali");
Menu menu_8 = new Menu(mntmJavaToSmali);
mntmJavaToSmali.setMenu(menu_8);
MenuItem mntmCompile = new MenuItem(menu_8, SWT.NONE);
mntmCompile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
javaToSmaliController.tryToCompileJava(javaToSmaliJavaStyledText, javaToSmaliSmaliStyledText);
}
});
mntmCompile.setText("Convert Java to Smali");
new MenuItem(menu_8, SWT.SEPARATOR);
MenuItem mntmConfigureClasspath = new MenuItem(menu_8, SWT.NONE);
mntmConfigureClasspath.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
Object ret = new ConfigurationDialog(shlOterTool).open();
}
});
mntmConfigureClasspath.setText("Configure classpath");
MenuItem mntmAddAndroidjarTo = new MenuItem(menu_8, SWT.NONE);
mntmAddAndroidjarTo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
OterWorkshop.addAndroidjarToClasspath();
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, e.getMessage());
return;
}
GuiWorkshop.messageDialog(shlOterTool, "Sucessfull added android.jar to classpath. View File->Configure to view changes.");
}
});
mntmAddAndroidjarTo.setText("Add android.jar to classpath");
MenuItem mntmTools = new MenuItem(menu, SWT.CASCADE);
mntmTools.setText("Tools");
Menu menu_6 = new Menu(mntmTools);
mntmTools.setMenu(menu_6);
MenuItem mntmLaunchAndroid = new MenuItem(menu_6, SWT.NONE);
mntmLaunchAndroid.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
setStatus("Launging android.");
BackgroundCommand c = new BackgroundCommand(OterStatics.getAndroidCommand());
try {
c.execute();
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not execute android: " + e.getMessage());
}
clearStatus();
}
});
mntmLaunchAndroid.setText("Launch android");
MenuItem mntmRestartAdb = new MenuItem(menu_6, SWT.NONE);
mntmRestartAdb.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
setStatus("Restarting ADB");
try {
AdbWorkshop.restartAdb();
GuiWorkshop.messageDialog(shlOterTool, "Adb has been restarted.");
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not restart ADB: " + e.getMessage());
logger.error("Could not restart ADB:", e);
}
clearStatus();
}
});
mntmRestartAdb.setText("Restart ADB");
MenuItem mntmInstallCertificate = new MenuItem(menu_6, SWT.NONE);
mntmInstallCertificate.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
String certfile = GuiWorkshop.selectFile(shlOterTool, new String[] { "*" });
if (certfile != null) {
setStatus("Installing certificate: " + certfile);
try {
AdbWorkshop.installCert(new File(certfile), "changeit");
GuiWorkshop.messageDialog(shlOterTool, "The certificate has been sucessfully installed");
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not install cert: " + e.getMessage());
logger.error("Could not install cert:", e);
}
clearStatus();
}
}
});
mntmInstallCertificate.setText("Install Certificate");
MenuItem mntmInstallApk = new MenuItem(menu_6, SWT.NONE);
mntmInstallApk.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
installApk();
}
});
mntmInstallApk.setText("Install APK");
MenuItem mntmCreateAvd = new MenuItem(menu_6, SWT.NONE);
mntmCreateAvd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
//installApk();
CreateAvdBean ret = new CreateAvdDialog(getShell()).open();
if (ret != null) {
avdController.createAvd(ret);
}
}
});
mntmCreateAvd.setText("Create Android Virtual Device");
tabFolder = new CTabFolder(shlOterTool, SWT.BORDER | SWT.BOTTOM);
tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
// If no tab is selected
String selectedTab = tabFolder.getSelection().getText();
if (selectedTab.equals("Package Manager")) {
if (packageManagerTabFolder.getSelection() == null) {
packageManagerTabFolder.setSelection(0);
}
if (apkTable.getTable().getItemCount() == 0) {
apkTable.loadPackages();
}
} else if (selectedTab.equals("Smali")) {
if (smaliTabFolder.getSelection() == null) {
smaliTabFolder.setSelection(0);
}
}
}
});
FormData fd_tabFolder = new FormData();
fd_tabFolder.top = new FormAttachment(0, 3);
fd_tabFolder.right = new FormAttachment(100);
fd_tabFolder.left = new FormAttachment(0, 3);
tabFolder.setLayoutData(fd_tabFolder);
tabFolder.setSimple(false);
tabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
CTabItem tbtmLogcat = new CTabItem(tabFolder, SWT.NONE);
tbtmLogcat.setText("LogCat");
Composite composite = new Composite(tabFolder, SWT.NONE);
tbtmLogcat.setControl(composite);
composite.setLayout(new GridLayout(1, false));
Composite composite_1 = new Composite(composite, SWT.NONE);
GridLayout gl_composite_1 = new GridLayout(3, false);
gl_composite_1.horizontalSpacing = 0;
gl_composite_1.marginHeight = 0;
gl_composite_1.marginWidth = 0;
gl_composite_1.verticalSpacing = 0;
composite_1.setLayout(gl_composite_1);
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
Composite composite_11 = new Composite(composite_1, SWT.NONE);
composite_11.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
GridLayout gl_composite_11 = new GridLayout(1, false);
gl_composite_11.horizontalSpacing = 0;
gl_composite_11.marginHeight = 0;
gl_composite_11.marginWidth = 0;
gl_composite_11.verticalSpacing = 0;
composite_11.setLayout(gl_composite_11);
Label lblFilter = new Label(composite_11, SWT.HORIZONTAL);
lblFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
lblFilter.setText("Message Filter:");
logcatTextFilter = new Text(composite_11, SWT.BORDER);
logcatTextFilter.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent arg0) {
logcatController.reFilterTable();
}
});
logcatTextFilter.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Composite composite_2 = new Composite(composite_1, SWT.NONE);
composite_2.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
GridLayout gl_composite_2 = new GridLayout(8, false);
gl_composite_2.verticalSpacing = 0;
gl_composite_2.horizontalSpacing = 0;
gl_composite_2.marginWidth = 0;
gl_composite_2.marginHeight = 0;
composite_2.setLayout(gl_composite_2);
logcatCheckDebug = new Button(composite_2, SWT.CHECK);
logcatCheckDebug.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.reFilterTable();
}
});
logcatCheckDebug.setSize(57, 18);
logcatCheckDebug.setSelection(true);
logcatCheckDebug.setText("Debug");
logcatCheckInfo = new Button(composite_2, SWT.CHECK);
logcatCheckInfo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.reFilterTable();
}
});
logcatCheckInfo.setSize(43, 18);
logcatCheckInfo.setSelection(true);
logcatCheckInfo.setText("Info");
logcatCheckWarn = new Button(composite_2, SWT.CHECK);
logcatCheckWarn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.reFilterTable();
}
});
logcatCheckWarn.setSize(49, 18);
logcatCheckWarn.setSelection(true);
logcatCheckWarn.setText("Warn");
logcatCheckError = new Button(composite_2, SWT.CHECK);
logcatCheckError.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.reFilterTable();
}
});
logcatCheckError.setSize(49, 18);
logcatCheckError.setSelection(true);
logcatCheckError.setText("Error");
logcatCheckVerbose = new Button(composite_2, SWT.CHECK);
logcatCheckVerbose.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.reFilterTable();
}
});
logcatCheckVerbose.setSize(66, 18);
logcatCheckVerbose.setSelection(true);
logcatCheckVerbose.setText("Verbose");
new Label(composite_2, SWT.NONE);
new Label(composite_2, SWT.NONE);
this.logcatCheckAutoscroll = new Button(composite_2, SWT.CHECK);
logcatCheckAutoscroll.setSize(83, 18);
logcatCheckAutoscroll.setSelection(true);
logcatCheckAutoscroll.setText("Auto-scroll");
Composite composite_12 = new Composite(composite_1, SWT.NONE);
composite_12.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, false, false, 1, 1));
GridLayout gl_composite_12 = new GridLayout(4, false);
gl_composite_12.marginLeft = 5;
gl_composite_12.verticalSpacing = 0;
gl_composite_12.marginWidth = 0;
gl_composite_12.horizontalSpacing = 0;
gl_composite_12.marginHeight = 0;
composite_12.setLayout(gl_composite_12);
Button btnClear = new Button(composite_12, SWT.NONE);
btnClear.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatTable.removeAll();
}
});
btnClear.setText("Clear");
Button btnStart = new Button(composite_12, SWT.NONE);
btnStart.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
public void widgetSelected(SelectionEvent arg0) {
try {
logcatController.start();
} catch (Exception e) {
GuiWorkshop.messageError(shlOterTool, "Could not start: " + e.getMessage());
logger.error("Could not start logcat:", e);
}
}
});
btnStart.setText("Start");
Button btnStop = new Button(composite_12, SWT.NONE);
btnStop.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
public void widgetSelected(SelectionEvent arg0) {
logcatController.stop();
}
});
btnStop.setText("Stop");
new Label(composite_12, SWT.NONE);
logcatTable = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
logcatTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
logcatTable.addMouseWheelListener(new MouseWheelListener() {
public void mouseScrolled(MouseEvent arg0) {
//if(arg0.y == logcatTable.getLocation().y)
//logger.debug(arg0.y + ":" + logcatTable.getSize().y);
//logcatTable.getBounds().y
//logcatController.stopAutoscroll();
}
});
logcatTable.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
}
public void widgetSelected(SelectionEvent arg0) {
logcatController.stopAutoscroll();
}
});
logcatTable.setHeaderVisible(true);
logcatTable.setLinesVisible(true);
TableColumn tblclmnDate = new TableColumn(logcatTable, SWT.NONE);
tblclmnDate.setWidth(111);
tblclmnDate.setText("Timestamp");
TableColumn tblclmnNewColumn = new TableColumn(logcatTable, SWT.NONE);
tblclmnNewColumn.setWidth(55);
tblclmnNewColumn.setText("Level");
TableColumn tblclmnClass = new TableColumn(logcatTable, SWT.NONE);
tblclmnClass.setWidth(86);
tblclmnClass.setText("Class");
TableColumn tblclmnPid = new TableColumn(logcatTable, SWT.NONE);
tblclmnPid.setWidth(34);
tblclmnPid.setText("PID");
TableColumn tblclmnMessage = new TableColumn(logcatTable, SWT.NONE);
tblclmnMessage.setWidth(600);
tblclmnMessage.setText("Message");
Menu menu_7 = new Menu(logcatTable);
logcatTable.setMenu(menu_7);
MenuItem mntmCopy = new MenuItem(menu_7, SWT.NONE);
mntmCopy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatController.copy();
}
});
mntmCopy.setText("Copy");
MenuItem mntmCle = new MenuItem(menu_7, SWT.NONE);
mntmCle.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logcatTable.removeAll();
}
});
mntmCle.setText("Clear");
statusLabel = new Label(shlOterTool, SWT.NONE);
fd_tabFolder.bottom = new FormAttachment(statusLabel, -6);
CTabItem tbtmFsdiff = new CTabItem(tabFolder, SWT.NONE);
tbtmFsdiff.setText("FsDiff");
Composite composite_5 = new Composite(tabFolder, SWT.NONE);
tbtmFsdiff.setControl(composite_5);
composite_5.setLayout(new FillLayout(SWT.HORIZONTAL));
fsDiffSashForm = new SashForm(composite_5, SWT.NONE);
Composite composite_6 = new Composite(fsDiffSashForm, SWT.NONE);
composite_6.setLayout(new FormLayout());
Label lblFirst = new Label(composite_6, SWT.NONE);
FormData fd_lblFirst = new FormData();
fd_lblFirst.top = new FormAttachment(1);
fd_lblFirst.left = new FormAttachment(0);
lblFirst.setLayoutData(fd_lblFirst);
lblFirst.setText("First");
fsDiffFirstTree = new Tree(composite_6, SWT.BORDER);
FormData fd_tree_2 = new FormData();
fd_tree_2.bottom = new FormAttachment(100);
fd_tree_2.right = new FormAttachment(100);
fd_tree_2.top = new FormAttachment(lblFirst, 0);
fd_tree_2.left = new FormAttachment(0);
fsDiffFirstTree.setLayoutData(fd_tree_2);
Composite composite_7 = new Composite(fsDiffSashForm, SWT.NONE);
composite_7.setLayout(new FormLayout());
Label lblSecond = new Label(composite_7, SWT.NONE);
FormData fd_lblSecond = new FormData();
fd_lblSecond.top = new FormAttachment(1);
fd_lblSecond.left = new FormAttachment(0);
lblSecond.setLayoutData(fd_lblSecond);
lblSecond.setText("Second");
fsDiffSecondTree = new Tree(composite_7, SWT.BORDER);
FormData fd_tree_3 = new FormData();
fd_tree_3.bottom = new FormAttachment(100);
fd_tree_3.right = new FormAttachment(100);
fd_tree_3.top = new FormAttachment(lblSecond, 0);
fd_tree_3.left = new FormAttachment(lblSecond, 0, SWT.LEFT);
fsDiffSecondTree.setLayoutData(fd_tree_3);
Composite composite_8 = new Composite(fsDiffSashForm, SWT.NONE);
composite_8.setLayout(new FormLayout());
Label lblDifferences = new Label(composite_8, SWT.NONE);
FormData fd_lblDifferences = new FormData();
fd_lblDifferences.top = new FormAttachment(1);
fd_lblDifferences.left = new FormAttachment(0);
lblDifferences.setLayoutData(fd_lblDifferences);
lblDifferences.setText("Differences");
fsDifferencesTree = new Tree(composite_8, SWT.BORDER);
fsDifferencesTree.setHeaderVisible(true);
FormData fd_tree_4 = new FormData();
fd_tree_4.bottom = new FormAttachment(100);
fd_tree_4.right = new FormAttachment(100);
fd_tree_4.top = new FormAttachment(lblDifferences, 0);
fd_tree_4.left = new FormAttachment(lblDifferences, 0, SWT.LEFT);
fsDifferencesTree.setLayoutData(fd_tree_4);
TreeColumn trclmnName = new TreeColumn(fsDifferencesTree, SWT.NONE);
trclmnName.setWidth(330);
trclmnName.setText("Name");
TreeColumn trclmnPermissions = new TreeColumn(fsDifferencesTree, SWT.NONE);
trclmnPermissions.setWidth(72);
trclmnPermissions.setText("Permissions");
TreeColumn trclmnGroup = new TreeColumn(fsDifferencesTree, SWT.NONE);
trclmnGroup.setWidth(50);
trclmnGroup.setText("Group");
TreeColumn trclmnUser = new TreeColumn(fsDifferencesTree, SWT.NONE);
trclmnUser.setWidth(50);
trclmnUser.setText("User");
TreeColumn trclmnSize = new TreeColumn(fsDifferencesTree, SWT.NONE);
trclmnSize.setWidth(40);
trclmnSize.setText("Size");
TreeColumn trclmnModified = new TreeColumn(fsDifferencesTree, SWT.NONE);
trclmnModified.setWidth(140);
trclmnModified.setText("Modified");
fsDiffSashForm.setWeights(new int[] { 1, 1, 3 });
CTabItem tbtmApktool = new CTabItem(tabFolder, SWT.NONE);
tbtmApktool.setText("Smali");
Composite composite_3 = new Composite(tabFolder, SWT.NONE);
tbtmApktool.setControl(composite_3);
composite_3.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm sashForm_1 = new SashForm(composite_3, SWT.NONE);
smaliTree = new Tree(sashForm_1, SWT.BORDER);
smaliTree.setLinesVisible(true);
smaliTree.setHeaderVisible(true);
smaliTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
TreeItem[] items = smaliTree.getSelection();
if (items.length > 0) {
TreeItem sel = items[0];
if (sel.getItemCount() == 0) {
String name = sel.getText();
setStatus("Loading: " + name);
TreeItem parent = sel.getParentItem();
String pkg = (parent == null) ? "" : parent.getText();
smaliController.loadSmaliSource(pkg, name);
} else {
sel.setExpanded(true);
}
clearStatus();
}
}
});
smaliTabFolder = new CTabFolder(sashForm_1, SWT.BORDER);
smaliTabFolder.setSimple(false);
smaliTabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
smaliTabSearchTab = new CTabItem(smaliTabFolder, SWT.NONE);
smaliTabSearchTab.setText("Search");
Composite composite_9 = new Composite(smaliTabFolder, SWT.NONE);
smaliTabSearchTab.setControl(composite_9);
GridLayout gl_composite_9 = new GridLayout(1, false);
gl_composite_9.marginTop = 5;
gl_composite_9.verticalSpacing = 0;
gl_composite_9.marginHeight = 0;
gl_composite_9.horizontalSpacing = 0;
composite_9.setLayout(gl_composite_9);
smaliSearchText = new Text(composite_9, SWT.BORDER);
smaliSearchText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.character == 13) {
smaliController.search();
}
}
});
smaliSearchText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Composite composite_10 = new Composite(composite_9, SWT.NONE);
GridLayout gl_composite_10 = new GridLayout(2, false);
gl_composite_10.marginBottom = 5;
gl_composite_10.marginHeight = 0;
gl_composite_10.verticalSpacing = 0;
gl_composite_10.marginWidth = 0;
gl_composite_10.horizontalSpacing = 0;
composite_10.setLayout(gl_composite_10);
smaliSearchIgnoreCase = new Button(composite_10, SWT.CHECK);
smaliSearchIgnoreCase.setBounds(0, 0, 93, 18);
smaliSearchIgnoreCase.setText("Ignore Case");
smaliSearchRegex = new Button(composite_10, SWT.CHECK);
smaliSearchRegex.setBounds(0, 0, 93, 18);
smaliSearchRegex.setText("Regex");
smaliSearchTable = new Table(composite_9, SWT.BORDER | SWT.FULL_SELECTION);
smaliSearchTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
TableItem[] selected = smaliSearchTable.getSelection();
if (selected.length > 0) {
smaliController.loadSmaliSourceWithLineNumber((String) selected[0].getData(SmaliController.PACKAGE), (String) selected[0].getData(SmaliController.NAME), ((Integer) selected[0].getData(SmaliController.LINENUMBER)).intValue());
}
}
});
smaliSearchTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
smaliSearchTable.setBounds(0, 0, 3, 19);
smaliSearchTable.setHeaderVisible(true);
smaliSearchTable.setLinesVisible(true);
TableColumn tblclmnClass_1 = new TableColumn(smaliSearchTable, SWT.NONE);
tblclmnClass_1.setWidth(200);
tblclmnClass_1.setText("Class");
TableColumn tblclmnContents = new TableColumn(smaliSearchTable, SWT.NONE);
tblclmnContents.setWidth(750);
tblclmnContents.setText("Contents");
StyledText styledText = new StyledText(smaliTabFolder, SWT.BORDER);
sashForm_1.setWeights(new int[] { 1, 5 });
CTabItem tbtmJavaToSmali = new CTabItem(tabFolder, SWT.NONE);
tbtmJavaToSmali.setText("Java to Smali");
Composite composite_13 = new Composite(tabFolder, SWT.NONE);
tbtmJavaToSmali.setControl(composite_13);
composite_13.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm sashForm = new SashForm(composite_13, SWT.NONE);
Composite composite_14 = new Composite(sashForm, SWT.NONE);
GridLayout gl_composite_14 = new GridLayout(1, false);
gl_composite_14.verticalSpacing = 0;
gl_composite_14.marginWidth = 0;
gl_composite_14.marginHeight = 0;
gl_composite_14.horizontalSpacing = 0;
composite_14.setLayout(gl_composite_14);
Label lblJava = new Label(composite_14, SWT.NONE);
lblJava.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
lblJava.setText("Java");
javaToSmaliJavaStyledText = new StyledText(composite_14, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
javaToSmaliJavaStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
javaToSmaliJavaStyledText.setText("import android.util.Log;\n\npublic class OterTool {\n\n // Youll need to include everything that would exist in a full \n // java source file. I typically just write a class in Eclipse\n // and allow it to handle all imports, and paste it here.\n\n // You will also need to include the android.jar file in the \n // classpath to use thing like 'Log'. This can be configured\n // through the configuration dialog (File->Configure) or you\n // can attempt to have otertool attempt to automatically add it\n // for you through Java to Smali->Add android.jar to classpath\n\n public static void main(String[] args) {\n // Placing a method here, with its arguments will show you \n // the calling convention, and allow you to easily paste\n // the code in the smali class\n oterToolMethod(\"calling argument\");\n Log.e(\"Tag\", \"Test\");\n }\n \n public static void oterToolMethod(String arg){\n // You can paste this portion of the smali code directly in\n // the end of the original package, and call it from everywhere\n System.out.println(arg);\n }\n}");
//javaToSmaliJavaStyledText.addLineStyleListener(new JavaLineStyler());
Composite composite_15 = new Composite(sashForm, SWT.NONE);
GridLayout gl_composite_15 = new GridLayout(1, false);
gl_composite_15.marginHeight = 0;
gl_composite_15.verticalSpacing = 0;
gl_composite_15.marginWidth = 0;
gl_composite_15.horizontalSpacing = 0;
composite_15.setLayout(gl_composite_15);
Label lblSmali = new Label(composite_15, SWT.NONE);
lblSmali.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
lblSmali.setText("Smali");
javaToSmaliSmaliStyledText = new StyledText(composite_15, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
javaToSmaliSmaliStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
javaToSmaliSmaliStyledText.addLineStyleListener(new SmaliLineStyler());
sashForm.setWeights(new int[] { 1, 1 });
CTabItem tbtmPackageManager = new CTabItem(tabFolder, SWT.NONE);
tbtmPackageManager.setText("Package Manager");
Composite composite_4 = new Composite(tabFolder, SWT.NONE);
tbtmPackageManager.setControl(composite_4);
composite_4.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm packageManagerSashForm = new SashForm(composite_4, SWT.NONE);
apkTable = new ApkTable(packageManagerSashForm, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
apkTable.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
logger.debug(apkTable.getTable().getSelection().length);
packageManagerController.loadPackageDetails(apkTable.getTable().getSelection());
}
});
Menu menu_5 = new Menu(apkTable.getTable());
apkTable.getTable().setMenu(menu_5);
MenuItem mntmInstall = new MenuItem(menu_5, SWT.NONE);
mntmInstall.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
installApk();
apkTable.loadPackages();
}
});
mntmInstall.setText("Install APK");
MenuItem mntmUninstall = new MenuItem(menu_5, SWT.NONE);
mntmUninstall.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
setStatus("UnInstalling package: " + apkTable.getTable().getSelection()[0].getText(0));
packageManagerController.uninstallPackages(apkTable.getTable().getSelection());
clearStatus();
apkTable.loadPackages();
}
});
mntmUninstall.setText("Uninstall Package(s)");
MenuItem mntmPullPackages = new MenuItem(menu_5, SWT.NONE);
mntmPullPackages.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
String dir = GuiWorkshop.selectDirectory(shlOterTool);
if (dir != null) {
packageManagerController.pullPackages(dir);
}
}
});
mntmPullPackages.setText("Pull Package(s)");
new MenuItem(menu_5, SWT.SEPARATOR);
MenuItem mntmRefreshList = new MenuItem(menu_5, SWT.NONE);
mntmRefreshList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
apkTable.loadPackages();
}
});
mntmRefreshList.setText("Refresh List");
packageManagerTabFolder = new CTabFolder(packageManagerSashForm, SWT.BORDER | SWT.FLAT);
packageManagerTabFolder.setSimple(false);
packageManagerTabFolder.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
CTabItem tbtmAapt = new CTabItem(packageManagerTabFolder, SWT.NONE);
tbtmAapt.setText("Aapt");
Composite composite_16 = new Composite(packageManagerTabFolder, SWT.NONE);
tbtmAapt.setControl(composite_16);
GridLayout gl_composite_16 = new GridLayout(1, false);
gl_composite_16.verticalSpacing = 0;
gl_composite_16.marginWidth = 0;
gl_composite_16.marginHeight = 0;
gl_composite_16.horizontalSpacing = 0;
composite_16.setLayout(gl_composite_16);
packageManagerStyledText = new StyledText(composite_16, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
packageManagerStyledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
CTabItem tbtmFiles = new CTabItem(packageManagerTabFolder, SWT.NONE);
tbtmFiles.setText("Files");
SashForm sashForm_2 = new SashForm(packageManagerTabFolder, SWT.NONE);
tbtmFiles.setControl(sashForm_2);
Composite composite_17 = new Composite(sashForm_2, SWT.NONE);
GridLayout gl_composite_17 = new GridLayout(1, false);
gl_composite_17.verticalSpacing = 0;
gl_composite_17.marginWidth = 0;
gl_composite_17.marginHeight = 0;
gl_composite_17.horizontalSpacing = 0;
composite_17.setLayout(gl_composite_17);
packageManagerFilesTree = new Tree(composite_17, SWT.BORDER);
packageManagerFilesTree.setHeaderVisible(true);
packageManagerFilesTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent arg0) {
try {
Tree tree = packageManagerFilesTree;
if (tree.getSelectionCount() == 1) {
TreeItem[] items = tree.getSelection();
FsNode node = (FsNode) items[0].getData(FsNode.class.getName());
for (CTabItem cti : packageManagerFilesTabs.getItems()) {
if (cti.getText().equals(node.getName())) {
packageManagerFilesTabs.setSelection(cti);
return;
}
}
logger.debug("Selected item: " + node.toString());
packageManagerController.loadFileContentsToTab(node);
}
} catch (Exception e) {
logger.error("Could not load file: ", e);
GuiWorkshop.messageDialog(shlOterTool, "Could not load file: " + e.getMessage());
}
}
});
packageManagerFilesTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Menu menu_9 = new Menu(packageManagerFilesTree);
packageManagerFilesTree.setMenu(menu_9);
MenuItem mntmSqlite = new MenuItem(menu_9, SWT.NONE);
mntmSqlite.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (packageManagerFilesTree.getSelectionCount() == 1) {
try {
TreeItem[] items = packageManagerFilesTree.getSelection();
FsNode node = (FsNode) items[0].getData(FsNode.class.getName());
packageManagerController.loadFileContentsToSQLiteTab(node);
} catch (Exception e) {
logger.error("Could not load file: ", e);
GuiWorkshop.messageDialog(shlOterTool, "Could not load file: " + e.getMessage());
}
}
}
});
mntmSqlite.setText("SQLite view");
MenuItem mntmHexView = new MenuItem(menu_9, SWT.NONE);
mntmHexView.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (packageManagerFilesTree.getSelectionCount() == 1) {
try {
TreeItem[] items = packageManagerFilesTree.getSelection();
FsNode node = (FsNode) items[0].getData(FsNode.class.getName());
packageManagerController.loadFileContentsToHexTab(node);
} catch (Exception e) {
logger.error("Could not load file: ", e);
GuiWorkshop.messageDialog(shlOterTool, "Could not load file: " + e.getMessage());
}
}
}
});
mntmHexView.setText("Hex view");
MenuItem mntmTextView = new MenuItem(menu_9, SWT.NONE);
mntmTextView.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (packageManagerFilesTree.getSelectionCount() == 1) {
try {
TreeItem[] items = packageManagerFilesTree.getSelection();
FsNode node = (FsNode) items[0].getData(FsNode.class.getName());
packageManagerController.loadFileContentsToTextTab(node);
} catch (Exception e) {
logger.error("Could not load file: ", e);
GuiWorkshop.messageDialog(shlOterTool, "Could not load file: " + e.getMessage());
}
}
}
});
mntmTextView.setText("Text view");
MenuItem mntmSaveFileView = new MenuItem(menu_9, SWT.NONE);
mntmSaveFileView.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
if (packageManagerFilesTree.getSelectionCount() == 1) {
try {
TreeItem[] items = packageManagerFilesTree.getSelection();
FsNode node = (FsNode) items[0].getData(FsNode.class.getName());
String file = GuiWorkshop.selectSaveFile(shlOterTool, new String[] {});
packageManagerController.saveFileAs(node, file);
GuiWorkshop.messageDialog(shlOterTool, "Your file has been saved.");
} catch (Exception e) {
logger.error("Could not load file: ", e);
GuiWorkshop.messageDialog(shlOterTool, "Could not save file: " + e.getMessage());
}
}
}
});
mntmSaveFileView.setText("Save File...");
Composite composite_18 = new Composite(sashForm_2, SWT.NONE);
GridLayout gl_composite_18 = new GridLayout(1, false);
gl_composite_18.verticalSpacing = 0;
gl_composite_18.marginWidth = 0;
gl_composite_18.marginHeight = 0;
gl_composite_18.horizontalSpacing = 0;
composite_18.setLayout(gl_composite_18);
sashForm_2.setWeights(new int[] { 197, 525 });
packageManagerFilesTabs = new CTabFolder(composite_18, SWT.BORDER);
packageManagerFilesTabs.setSimple(false);
packageManagerFilesTabs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
packageManagerFilesTabs.setSelectionBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
packageManagerAndroidManifestTab = new CTabItemWithTreeForAndroidManifest(packageManagerTabFolder, SWT.NONE);
packageManagerAndroidManifestTab.setText("AndroidManifest");
packageManagerSashForm.setWeights(new int[] { 1, 2 });
FormData fd_statusLabel = new FormData();
fd_statusLabel.bottom = new FormAttachment(100, -2);
fd_statusLabel.left = new FormAttachment(tabFolder, 0, SWT.LEFT);
fd_statusLabel.right = new FormAttachment(100);
statusLabel.setLayoutData(fd_statusLabel);
statusLabel.setText("Welcome");
}
use of org.eclipse.swt.custom.SashForm in project ACS by ACS-Community.
the class ReductionsView method createViewWidgets.
private void createViewWidgets(Composite parent) {
_addElement = new Listener() {
public void handleEvent(Event event) {
TreeItem sel = null;
TreeItem item = null;
if (_tree.getSelection() == null || _tree.getSelection().length == 0)
return;
sel = _tree.getSelection()[0];
NodeType type = (NodeType) sel.getData();
item = sel;
if (type == NodeType.NODE_REDUCTION_PARENT_DATA || type == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA)
item = sel.getParentItem();
type = (NodeType) item.getData();
java.util.List<FaultFamily> ffs = _alarmManager.getAllAlarms();
java.util.List<String> ffnames = new ArrayList<String>();
for (FaultFamily ff : ffs) {
if (ff.getFaultCodeCount() > 0 && ff.getFaultMemberCount() > 0)
ffnames.add(ff.getName());
}
Collections.sort(ffnames, IGNORE_CASE_ORDER);
ListDialog dialog = new ListDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
dialog.setTitle("Create Reduction Rule");
dialog.setMessage("Select Parent Fault Family");
dialog.setBlockOnOpen(true);
dialog.setInput(ffnames);
dialog.setContentProvider(new ArrayContentProvider());
dialog.setLabelProvider(new LabelProvider());
dialog.open();
if (dialog.getReturnCode() == InputDialog.CANCEL)
return;
String ffname = (String) dialog.getResult()[0];
FaultMember[] fms = _alarmManager.getFaultFamily(ffname).getFaultMember();
java.util.List<String> fmnames = new ArrayList<String>();
for (FaultMember fm : fms) {
fmnames.add(fm.getName());
}
Collections.sort(ffnames, IGNORE_CASE_ORDER);
dialog = new ListDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
dialog.setTitle("Create Reduction Rule");
dialog.setMessage("Select Parent Fault Member");
dialog.setBlockOnOpen(true);
dialog.setInput(fmnames);
dialog.setContentProvider(new ArrayContentProvider());
dialog.setLabelProvider(new LabelProvider());
dialog.open();
if (dialog.getReturnCode() == InputDialog.CANCEL)
return;
String fmname = (String) dialog.getResult()[0];
FaultCode[] fcs = _alarmManager.getFaultFamily(ffname).getFaultCode();
java.util.List<String> fcvalues = new ArrayList<String>();
for (FaultCode fc : fcs) {
fcvalues.add(Integer.toString(fc.getValue()));
}
Collections.sort(ffnames, IGNORE_CASE_ORDER);
dialog = new ListDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
dialog.setTitle("Create Reduction Rule");
dialog.setMessage("Select Parent Fault Code");
dialog.setBlockOnOpen(true);
dialog.setInput(fcvalues);
dialog.setContentProvider(new ArrayContentProvider());
dialog.setLabelProvider(new LabelProvider());
dialog.open();
if (dialog.getReturnCode() == InputDialog.CANCEL)
return;
String fcvalue = (String) dialog.getResult()[0];
ReductionRule parent = null;
boolean error = false;
if (type == NodeType.NODE_REDUCTION) {
parent = _reductionManager.getNRParentByTriplet(ffname, fmname, Integer.parseInt(fcvalue));
TreeItem[] chs = _tree.getItems()[0].getItems();
for (TreeItem ch : chs) {
if (ch.getText().compareTo("<" + ffname + "," + fmname + "," + fcvalue + ">") == 0)
error = true;
}
} else if (type == NodeType.MULTIPLICITY_REDUCTION) {
parent = _reductionManager.getMRParentByTriplet(ffname, fmname, Integer.parseInt(fcvalue));
TreeItem[] chs = _tree.getItems()[1].getItems();
for (TreeItem ch : chs) {
if (ch.getText().compareTo("<" + ffname + "," + fmname + "," + fcvalue + ">") == 0)
error = true;
}
}
if (error || parent != null) {
ErrorDialog edialog = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Reduction Rule Already Exists", "The reduction rule you are trying to create already exists", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "The reduction rule parent already exists"), IStatus.ERROR);
edialog.setBlockOnOpen(true);
edialog.open();
return;
} else
parent = new ReductionRule(_alarmManager.getAlarm(ffname + ":" + fmname + ":" + fcvalue));
TreeItem pTree = new TreeItem(item, SWT.NONE);
pTree.setText("<" + ffname + "," + fmname + "," + fcvalue + ">");
if (type == NodeType.NODE_REDUCTION) {
pTree.setData(NodeType.NODE_REDUCTION_PARENT_DATA);
parent.setIsNodeReduction(true);
} else if (type == NodeType.MULTIPLICITY_REDUCTION) {
pTree.setData(NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA);
parent.setIsNodeReduction(false);
}
_tree.setSelection(pTree);
Event e = new Event();
_tree.notifyListeners(SWT.Selection, e);
}
};
_addRule = new Listener() {
public void handleEvent(Event event) {
Table t = (Table) event.widget;
if (event.type == SWT.KeyUp)
if (!(event.keyCode == SWT.CR || event.keyCode == ' '))
return;
if (event.type == SWT.MouseDoubleClick) {
Point pt = new Point(event.x, event.y);
if (t.getItem(pt) == null)
return;
}
boolean isNode;
if (_tree.getSelection() == null || _tree.getSelection().length == 0)
return;
TreeItem tmp1 = _tree.getSelection()[0];
if ((NodeType) _tree.getSelection()[0].getData() == NodeType.NODE_REDUCTION_PARENT_DATA)
isNode = true;
else if ((NodeType) _tree.getSelection()[0].getData() == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA)
isNode = false;
else
return;
String[] tr = getTriplet(tmp1.getText());
ReductionRule parent;
if (isNode)
parent = _reductionManager.getNRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
else
parent = _reductionManager.getMRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
if (t.getSelection() == null || t.getSelection().length == 0)
return;
TableItem item = t.getSelection()[0];
Alarm p, c;
if (parent == null) {
if (isNode)
p = _alarmManager.getAlarm(_NRParentFFCombo.getText() + ":" + _NRParentFMCombo.getText() + ":" + _NRParentFCCombo.getText());
else
p = _alarmManager.getAlarm(_MRParentFFCombo.getText() + ":" + _MRParentFMCombo.getText() + ":" + _MRParentFCCombo.getText());
if (p == null) {
if (isNode)
_NRParentErrorMessageLabel.setText("Couldn't find parent alarm.");
else
_MRParentErrorMessageLabel.setText("Couldn't find parent alarm.");
return;
}
c = null;
} else {
p = parent.getParent();
c = parent.getChild(item.getText());
}
if (c == null) {
//Add child
c = _alarmManager.getAlarm(item.getText());
if (c == null) {
if (isNode)
_NRParentErrorMessageLabel.setText("Couldn't find child alarm.");
else
_MRParentErrorMessageLabel.setText("Couldn't find child alarm.");
return;
}
try {
if (isNode)
_reductionManager.addNodeReductionRule(p, c);
else {
_reductionManager.addMultiReductionRule(p, c);
if (parent == null)
_reductionManager.updateMultiThreshold(p, Integer.parseInt(_MRParentThresholdText.getText()));
}
item.setImage(Activator.getDefault().getImageRegistry().get(Activator.IMG_TICKET));
if (parent == null)
_tree.getSelection()[0].setText("<" + p.getAlarmId().replace(':', ',') + ">");
if (isNode)
_NRParentErrorMessageLabel.setText("");
else
_MRParentErrorMessageLabel.setText("");
} catch (IllegalOperationException e) {
if (isNode)
_NRParentErrorMessageLabel.setText(e.getMessage());
else
_MRParentErrorMessageLabel.setText(e.getMessage());
}
} else {
//Remove child
try {
//ReductionRule rr;
if (isNode) {
_reductionManager.deleteNodeReductionRule(p, c);
//rr = _reductionManager.getNRParentByTriplet(p.getTriplet().getFaultFamily(), p.getTriplet().getFaultMember(), p.getTriplet().getFaultCode());
} else {
_reductionManager.deleteMultiReductionRule(p, c);
//rr = _reductionManager.getMRParentByTriplet(p.getTriplet().getFaultFamily(), p.getTriplet().getFaultMember(), p.getTriplet().getFaultCode());
}
} catch (IllegalOperationException e) {
e.printStackTrace();
}
item.setImage((org.eclipse.swt.graphics.Image) null);
}
fillMRParentChAlarmList(tr[0], tr[1], Integer.parseInt(tr[2]));
sortReductionRulesList();
Triplet t2 = p.getTriplet();
if (isNode)
selectElementFromTree("<" + t2.getFaultFamily() + "," + t2.getFaultMember() + "," + t2.getFaultCode() + ">", true);
else
selectElementFromTree("<" + t2.getFaultFamily() + "," + t2.getFaultMember() + "," + t2.getFaultCode() + ">", false);
}
};
_removeElement = new Listener() {
public void handleEvent(Event event) {
boolean choice = MessageDialog.openQuestion(ReductionsView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this element");
if (choice == true) {
TreeItem sel = null;
if (_tree.getSelection() == null || _tree.getSelection().length == 0)
return;
NodeType type = (NodeType) _tree.getSelection()[0].getData();
if (type == NodeType.NODE_REDUCTION || type == NodeType.MULTIPLICITY_REDUCTION)
return;
TreeItem item = _tree.getSelection()[0];
String[] tr = getTriplet(item.getText());
try {
if (type == NodeType.NODE_REDUCTION_PARENT_DATA) {
//Remove all the NODE REDUCTION Rules in which this node is parent.
ReductionRule rr = _reductionManager.getNRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
if (rr != null) {
Alarm p = rr.getParent();
List<Alarm> chL = rr.getChildren();
Alarm[] als = new Alarm[chL.size()];
chL.toArray(als);
for (int i = 0; i < als.length; i++) _reductionManager.deleteNodeReductionRule(p, als[i]);
}
} else if (type == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA) {
//Remove all the MULTIPLICITY REDUCTION Rules in which this node is a parent.
ReductionRule rr = _reductionManager.getMRParentByTriplet(tr[0], tr[1], Integer.parseInt(tr[2]));
if (rr != null) {
Alarm p = rr.getParent();
List<Alarm> chL = rr.getChildren();
Alarm[] als = new Alarm[chL.size()];
chL.toArray(als);
for (int i = 0; i < als.length; i++) _reductionManager.deleteMultiReductionRule(p, als[i]);
}
}
} catch (NullPointerException e) {
ErrorDialog error = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(ReductionsView.this.getViewSite().getShell(), "Cannot delete the item", e.getMessage(), new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
}
sel = _tree.getSelection()[0].getParentItem();
_tree.getSelection()[0].dispose();
_tree.setSelection(sel);
Event e = new Event();
_tree.notifyListeners(SWT.Selection, e);
}
}
};
_sash = new SashForm(parent, SWT.NONE);
_sash.setLayout(new FillLayout());
_reductionsComp = new Composite(_sash, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
_reductionsComp.setLayout(layout);
_treeGroup = new Group(_reductionsComp, SWT.SHADOW_ETCHED_IN);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
_treeGroup.setLayoutData(gd);
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_treeGroup.setLayout(gl);
_treeGroup.setText("Reduction Rules List");
_tree = new Tree(_treeGroup, SWT.VIRTUAL | SWT.BORDER);
gd = new GridData();
gd.verticalAlignment = SWT.FILL;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.grabExcessHorizontalSpace = true;
_tree.setLayoutData(gd);
Menu treePopUp = new Menu(parent);
/*
MenuItem treePopUpDelete = new MenuItem(treePopUp,SWT.PUSH);
treePopUpDelete.setText("Delete");
treePopUpDelete.addListener(SWT.Selection, _removeElement);
MenuItem treePopUpAddRule = new MenuItem(treePopUp,SWT.PUSH);
treePopUpAddRule.setText("Add Rule");
treePopUpAddRule.addListener(SWT.Selection, _addElement);
MenuItem treePopUpAddChildren = new MenuItem(treePopUp,SWT.PUSH);
treePopUpAddChildren.setText("Add Children");
//treePopUpAddChildren.addListener(SWT.Selection, _addElement);
*/
_tree.setMenu(treePopUp);
treePopUp.addListener(SWT.Show, new Listener() {
public void handleEvent(Event e) {
TreeItem sel = _tree.getSelection()[0];
NodeType type = (NodeType) sel.getData();
Menu treePopUp = _tree.getMenu();
MenuItem[] items = treePopUp.getItems();
for (int i = 0; i < items.length; i++) items[i].dispose();
MenuItem mitem;
switch(type) {
case NODE_REDUCTION:
mitem = new MenuItem(treePopUp, SWT.PUSH);
mitem.setText("Add Node Reduction Rule Parent");
mitem.addListener(SWT.Selection, _addElement);
break;
case NODE_REDUCTION_PARENT_DATA:
mitem = new MenuItem(treePopUp, SWT.PUSH);
mitem.setText("Delete Node Reduction Rules for this parent");
mitem.addListener(SWT.Selection, _removeElement);
break;
case MULTIPLICITY_REDUCTION:
mitem = new MenuItem(treePopUp, SWT.PUSH);
mitem.setText("Add Multiplicity Reduction Rule Parent");
mitem.addListener(SWT.Selection, _addElement);
break;
case MULTIPLICITY_REDUCTION_PARENT_DATA:
mitem = new MenuItem(treePopUp, SWT.PUSH);
mitem.setText("Delete Multiplicity Reduction Rules for this parent");
mitem.addListener(SWT.Selection, _removeElement);
break;
default:
for (int i = 0; i < items.length; i++) items[i].dispose();
break;
}
}
});
_tree.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
TreeItem[] tmp = ((Tree) e.widget).getSelection();
if (tmp == null || tmp.length == 0)
return;
TreeItem item = tmp[0];
NodeType type = (NodeType) item.getData();
Control c = _compInitial.getChildren()[0];
if (c instanceof Label) {
c.dispose();
_compInitial.layout();
c = _compInitial.getChildren()[0];
}
if (type == NodeType.NODE_REDUCTION) {
_NRParentGroup.setVisible(false);
((GridData) _NRParentGroup.getLayoutData()).exclude = true;
_MRParentGroup.setVisible(false);
((GridData) _MRParentGroup.getLayoutData()).exclude = true;
} else if (type == NodeType.NODE_REDUCTION_PARENT_DATA) {
_NRParentGroup.setVisible(true);
((GridData) _NRParentGroup.getLayoutData()).exclude = false;
_MRParentGroup.setVisible(false);
((GridData) _MRParentGroup.getLayoutData()).exclude = true;
String[] triplet = getTriplet(item.getText());
fillNRParentWidgets(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
_NRParentGroup.moveAbove(c);
_compInitial.layout();
} else if (type == NodeType.MULTIPLICITY_REDUCTION) {
_NRParentGroup.setVisible(false);
((GridData) _NRParentGroup.getLayoutData()).exclude = true;
_MRParentGroup.setVisible(false);
((GridData) _MRParentGroup.getLayoutData()).exclude = true;
} else if (type == NodeType.MULTIPLICITY_REDUCTION_PARENT_DATA) {
_NRParentGroup.setVisible(false);
((GridData) _NRParentGroup.getLayoutData()).exclude = true;
_MRParentGroup.setVisible(true);
((GridData) _MRParentGroup.getLayoutData()).exclude = false;
String[] triplet = getTriplet(item.getText());
fillMRParentWidgets(triplet[0], triplet[1], Integer.parseInt(triplet[2]));
_MRParentGroup.moveAbove(c);
_compInitial.layout();
}
}
});
/* Top widget of the right side */
_compInitial = new Composite(_sash, SWT.NONE);
_compInitial.setLayout(new GridLayout());
new Label(_compInitial, SWT.NONE).setText("Select a reduction rule");
/* NR/MR Details */
createNRParentWidgets();
createMRParentWidgets();
_NRParentGroup.setVisible(false);
_MRParentGroup.setVisible(false);
_sash.setWeights(new int[] { 3, 5 });
}
use of org.eclipse.swt.custom.SashForm in project ACS by ACS-Community.
the class CategoriesView method createViewWidgets.
private void createViewWidgets(Composite parent) {
SashForm sash = new SashForm(parent, SWT.HORIZONTAL);
sash.setLayout(new FillLayout());
/* Left pane */
Composite categoriesComp = new Composite(sash, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
categoriesComp.setLayout(layout);
_listGroup = new Group(categoriesComp, SWT.SHADOW_ETCHED_IN);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
_listGroup.setLayoutData(gd);
GridLayout gl = new GridLayout();
gl.numColumns = 1;
_listGroup.setLayout(gl);
_listGroup.setText("Categories List");
_categoriesList = new List(_listGroup, SWT.BORDER | SWT.V_SCROLL);
_categoriesList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
_categoriesList.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
Control c = _compInitial.getChildren()[0];
if (c instanceof Label) {
c.dispose();
}
_comp.setVisible(true);
_comp.layout();
/* and is shown with a "*" in the list */
if (_categoriesList.getSelection() == null || _categoriesList.getSelection().length == 0) {
_comp.setVisible(false);
_comp.layout();
return;
}
String categoryName = _categoriesList.getSelection()[0];
if (categoryName.startsWith("*"))
fillCategoryInfo((String) _categoriesList.getData());
else
fillCategoryInfo(categoryName);
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
}
});
/* Add and remove buttons */
Composite categoriesButtonsComp = new Composite(categoriesComp, SWT.NONE);
layout = new GridLayout();
layout.numColumns = 2;
categoriesButtonsComp.setLayout(layout);
categoriesButtonsComp.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
_addCategoryButton = new Button(categoriesButtonsComp, SWT.None);
_addCategoryButton.setText("Add");
_addCategoryButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
_deleteCategoryButton = new Button(categoriesButtonsComp, SWT.None);
_deleteCategoryButton.setText("Delete");
_deleteCategoryButton.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE));
Listener addCategory = new Listener() {
public void handleEvent(Event event) {
InputDialog dialog = new InputDialog(CategoriesView.this.getViewSite().getShell(), "New Category", "Enter the Category name", null, new IInputValidator() {
public String isValid(String newText) {
if (newText.trim().compareTo("") == 0)
return "The name is empty";
return null;
}
});
dialog.setBlockOnOpen(true);
dialog.open();
int returnCode = dialog.getReturnCode();
if (returnCode == InputDialog.OK) {
if (_categoryManager.getCategoryByPath(dialog.getValue()) != null) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Category already exist", "The Category " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "The Category " + dialog.getValue() + " already exists in the current configuration"), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
Category newCategory = new Category();
newCategory.setPath(dialog.getValue());
InputDialog dialog2 = new InputDialog(CategoriesView.this.getViewSite().getShell(), "Category Description", "Enter the Description for the Category", null, new IInputValidator() {
public String isValid(String newText) {
if (newText.trim().compareTo("") == 0)
return "The name is empty";
return null;
}
});
dialog2.setBlockOnOpen(true);
dialog2.open();
String description = dialog2.getValue();
if (description == null)
return;
if (returnCode == InputDialog.OK)
newCategory.setDescription(description);
java.util.List<String> ffnames = sortFullFaultFamilyList();
ListSelectionDialog dialog3 = new ListSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), ffnames, new ArrayContentProvider(), new LabelProvider(), "");
dialog3.setTitle("Fault Family Selection");
dialog3.setMessage("List of Fault Families");
dialog3.setBlockOnOpen(true);
dialog3.open();
Object[] ffselected = dialog3.getResult();
if (ffselected == null)
return;
if (ffselected.length == 0) {
try {
_categoryManager.addCategory(newCategory);
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Category already exist", "The Category " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
} else {
Alarms alarms = new Alarms();
for (int i = 0; i < ffselected.length; i++) {
try {
alarms.addFaultFamily(_alarmManager.getFaultFamily((String) ffselected[i]).getName());
//alarms.setFaultFamily(i, (String)ffselected[i]);
} catch (NullPointerException e) {
}
newCategory.setAlarms(alarms);
}
try {
_categoryManager.addCategory(newCategory);
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Category already exist", "The Category " + dialog.getValue() + " already exists in the current configuration", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
}
String[] items = new String[1];
items[0] = dialog.getValue();
refreshContents();
_categoriesList.setSelection(items);
Event e = new Event();
_categoriesList.notifyListeners(SWT.Selection, e);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
} else
return;
}
};
_addCategoryButton.addListener(SWT.Selection, addCategory);
Listener deleteCategory = new Listener() {
public void handleEvent(Event event) {
boolean choice = MessageDialog.openQuestion(CategoriesView.this.getViewSite().getShell(), "Confirmation", "Are you sure you want to delete this Category");
if (choice == true) {
String[] tmp = _categoriesList.getSelection();
if (tmp == null || tmp.length == 0) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Empty selection", "There are no Categories selected to be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", ""), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
String category = tmp[0];
if (category.startsWith("*")) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Cannot delete Category", "The Category cannot be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", "There must be one default category. Please select a different one before removing this category."), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
try {
_categoryManager.deleteCategory(_categoryManager.getCategoryByPath(category));
} catch (IllegalOperationException e) {
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Cannot delete Category", "The Category cannot be deleted", new Status(IStatus.ERROR, "cl.utfsm.acs.acg", e.getMessage()), IStatus.ERROR);
error.setBlockOnOpen(true);
error.open();
return;
}
String[] items = null;
if (_categoriesList.getSelection() != null && _categoriesList.getSelection().length != 0) {
items = _categoriesList.getSelection();
refreshContents();
if (items == null)
if (_categoriesList.getItemCount() > 0)
_categoriesList.setSelection(0);
} else
_categoriesList.setSelection(items);
Event e = new Event();
_categoriesList.notifyListeners(SWT.Selection, e);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
}
}
};
_deleteCategoryButton.addListener(SWT.Selection, deleteCategory);
/* To delete a FF from a given Category */
Listener deleteFaultFamily = new Listener() {
public void handleEvent(Event event) {
Category c = _categoryManager.getCategoryByPath(_pathText.getText());
try {
String[] ff = c.getAlarms().getFaultFamily();
Alarms alarms = new Alarms();
String[] temp = _ffList.getSelection();
//int j = 0;
for (int i = 0; i < ff.length; i++) {
if (ff[i].compareTo(temp[0]) == 0) {
_ffList.remove(temp[0]);
c.getAlarms().removeFaultFamily(ff[i]);
} else {
alarms.addFaultFamily(ff[i]);
//alarms.setFaultFamily(j, ff[i]);
//j++;
}
}
c.setAlarms(alarms);
_categoryManager.updateCategory(c, c);
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
boolean inUse = false;
boolean def = false;
String defCat = "";
for (Category cat : _categoryManager.getAllCategories()) {
String[] ffs = cat.getAlarms().getFaultFamily();
for (String tff : ffs) {
if (tff.compareTo(temp[0]) == 0)
inUse = true;
}
if (cat.getIsDefault()) {
def = true;
defCat = cat.getPath();
}
}
if (!inUse) {
String msg;
if (def)
msg = "Default category: " + defCat;
else
msg = "No default category";
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Fault Family isn't in any Categoty", "The Fault Family is not part of any Category", new Status(IStatus.WARNING, "cl.utfsm.acs.acg", "The Fault Family " + temp[0] + " is not part of any Category (" + msg + ")"), IStatus.WARNING);
error.setBlockOnOpen(true);
error.open();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
/* To delete all FF from a given Category */
Listener deleteAllFaultFamily = new Listener() {
public void handleEvent(Event event) {
Category c = _categoryManager.getCategoryByPath(_pathText.getText());
try {
String[] ff = c.getAlarms().getFaultFamily();
Alarms alarms = new Alarms();
for (int i = 0; i < ff.length; i++) {
_ffList.remove(ff[i]);
c.getAlarms().removeFaultFamily(ff[i]);
}
c.setAlarms(alarms);
_categoryManager.updateCategory(c, c);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
java.util.List<String> ffList = new ArrayList<String>();
boolean def = false;
String defCat = "";
for (String cff : ff) {
Boolean inUse = false;
for (Category cat : _categoryManager.getAllCategories()) {
String[] ffs = cat.getAlarms().getFaultFamily();
for (String tff : ffs) {
if (tff.compareTo(cff) == 0)
inUse = true;
}
if (cat.getIsDefault()) {
def = true;
defCat = cat.getPath();
}
}
if (!inUse)
ffList.add(cff);
}
if (ffList.size() > 0) {
String list = "";
for (String ffel : ffList) list = list + ffel + ", ";
list.substring(0, list.length() - 2);
String msg;
if (def)
msg = "Default category: " + defCat;
else
msg = "No default category";
ErrorDialog error = new ErrorDialog(CategoriesView.this.getViewSite().getShell(), "Fault Family isn't in any Categoty", "The Fault Family is not part of any Category", new Status(IStatus.WARNING, "cl.utfsm.acs.acg", "The Fault Family(ies) " + list + " is not part of any Category (" + msg + ")"), IStatus.WARNING);
error.setBlockOnOpen(true);
error.open();
}
} catch (Exception e) {
e.printStackTrace();
}
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
}
};
/* To add a new FF to a Category */
Listener addFaultFamily = new Listener() {
public void handleEvent(Event event) {
Category c = _categoryManager.getCategoryByPath(_pathText.getText());
java.util.List<String> currentffs = new ArrayList<String>();
try {
String[] ffss = c.getAlarms().getFaultFamily();
for (int i = 0; i < ffss.length; i++) {
currentffs.add(ffss[i]);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
java.util.List<String> ffnames = sortFullFaultFamilyList();
ListSelectionDialog dialog3 = new ListSelectionDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), ffnames, new ArrayContentProvider(), new LabelProvider(), "");
dialog3.setTitle("Fault Family Selection");
dialog3.setMessage("List of Fault Families");
dialog3.setBlockOnOpen(true);
if (currentffs != null)
dialog3.setInitialElementSelections(currentffs);
dialog3.open();
if (dialog3.getReturnCode() == InputDialog.OK) {
Object[] ffselected = dialog3.getResult();
try {
Alarms alarms = new Alarms();
for (int i = 0; i < ffselected.length; i++) alarms.addFaultFamily(_alarmManager.getFaultFamily((String) ffselected[i]).getName());
c.setAlarms(alarms);
_categoryManager.updateCategory(c, c);
sortCategoryFaultFamilyList(c.getPath());
} catch (Exception e) {
e.printStackTrace();
}
String[] items = _categoriesList.getSelection();
refreshContents();
_categoriesList.setSelection(items);
Event e = new Event();
_categoriesList.notifyListeners(SWT.Selection, e);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
if (_ffList.getItemCount() == 0)
_errorMessageLabel.setText("You have to select at least one Fault Family");
}
}
};
/* Initial label when no categories are selected */
_compInitial = new Composite(sash, SWT.NONE);
_compInitial.setLayout(new GridLayout());
new Label(_compInitial, SWT.NONE).setText("Select a category");
/* Fill the right pane Group that will be shown when
* a category is selected in the left list */
layout = new GridLayout();
layout.numColumns = 2;
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = SWT.FILL;
gridData.verticalAlignment = SWT.FILL;
_comp = new Group(_compInitial, SWT.SHADOW_ETCHED_IN);
_comp.setText("Category information");
_comp.setLayout(layout);
_comp.setLayoutData(gridData);
_pathLabel = new Label(_comp, SWT.NONE);
_pathLabel.setText("Category name");
_pathText = new Text(_comp, SWT.SINGLE | SWT.BORDER);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
_pathText.setLayoutData(gridData);
_descriptionLabel = new Label(_comp, SWT.NONE);
_descriptionLabel.setText("Category description");
_descriptionText = new Text(_comp, SWT.SINGLE | SWT.BORDER);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
_descriptionText.setLayoutData(gridData);
_isDefaultLabel = new Label(_comp, SWT.NONE);
_isDefaultLabel.setText("Is default category?");
_isDefaultCheck = new Button(_comp, SWT.CHECK);
_ffLabel = new Label(_comp, SWT.NONE);
_ffLabel.setText("Fault Families:");
gridData = new GridData();
gridData.verticalAlignment = SWT.TOP;
gridData.horizontalSpan = 2;
_ffLabel.setLayoutData(gridData);
_ffList = new List(_comp, SWT.V_SCROLL | SWT.BORDER);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalSpan = 2;
_ffList.setLayoutData(gridData);
_errorMessageLabel = new Label(_comp, SWT.NONE);
_errorMessageLabel.setText("A");
_errorMessageLabel.setForeground(getViewSite().getShell().getDisplay().getSystemColor(SWT.COLOR_RED));
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = 2;
_errorMessageLabel.setLayoutData(gd);
/* Adding a click right menu to modify the FF of a given Category */
Menu treePopUp1 = new Menu(parent);
MenuItem treePopUpAddFF = new MenuItem(treePopUp1, SWT.PUSH);
treePopUpAddFF.setText("Add a new Fault Family");
treePopUpAddFF.addListener(SWT.Selection, addFaultFamily);
MenuItem treePopUpDeleteFF = new MenuItem(treePopUp1, SWT.PUSH);
treePopUpDeleteFF.setText("Delete this Fault Family");
treePopUpDeleteFF.addListener(SWT.Selection, deleteFaultFamily);
MenuItem treePopUpDeleteAllFF = new MenuItem(treePopUp1, SWT.PUSH);
treePopUpDeleteAllFF.setText("Delete All Fault Families");
treePopUpDeleteAllFF.addListener(SWT.Selection, deleteAllFaultFamily);
_ffList.setMenu(treePopUp1);
/* Adding a click menu to add/delete Categories */
Menu treePopUp2 = new Menu(parent);
MenuItem treePopUpaddCategory = new MenuItem(treePopUp2, SWT.PUSH);
treePopUpaddCategory.setText("Add a new Category");
treePopUpaddCategory.addListener(SWT.Selection, addCategory);
MenuItem treePopUpdeleteCategory = new MenuItem(treePopUp2, SWT.PUSH);
treePopUpdeleteCategory.setText("Delete this Category");
treePopUpdeleteCategory.addListener(SWT.Selection, deleteCategory);
_categoriesList.setMenu(treePopUp2);
_comp.setVisible(false);
/* Set a weight for each side of the view */
sash.setWeights(new int[] { 3, 5 });
Listener updateCategory = new Listener() {
public void handleEvent(Event e) {
updateName();
}
};
_descriptionText.addListener(SWT.Modify, updateCategory);
_pathText.addListener(SWT.Modify, updateCategory);
_isDefaultCheck.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
String category;
if (_categoriesList.getSelection()[0].startsWith("*"))
category = (String) _categoriesList.getData();
else
category = _categoriesList.getSelection()[0];
if (_categoryManager.getCategoryByPath(category).getIsDefault() == true) {
_isDefaultCheck.setSelection(true);
MessageBox messageBox = new MessageBox(PlatformUI.getWorkbench().getDisplay().getActiveShell(), SWT.ICON_ERROR);
messageBox.setMessage("The Default Category always must exist, you can only change it");
messageBox.open();
} else {
_categoryManager.updateDefaultCategory(_categoryManager.getCategoryByPath(_categoriesList.getSelection()[0]));
String[] items = _categoriesList.getSelection();
refreshContents();
items[0] = "* " + items[0];
_categoriesList.setSelection(items);
Event e2 = new Event();
_categoriesList.notifyListeners(SWT.Selection, e2);
IWorkbenchWindow _window = getViewSite().getWorkbenchWindow();
IViewReference[] views = _window.getActivePage().getViewReferences();
IMyViewPart view = ((IMyViewPart) views[3].getView(false));
//view.refreshContents();
view.fillWidgets();
}
}
});
}
Aggregations