Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group naming wizard #1878

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lorenz Gerber - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.xxd.process.supplier.pca.ui.internal.provider;

import org.eclipse.chemclipse.model.statistics.ISample;
import org.eclipse.chemclipse.xxd.process.supplier.pca.ui.swt.SampleGroupAssignerListUI;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;

public class GroupNamingEditingSupport extends EditingSupport {

private CellEditor cellEditor;
private final SampleGroupAssignerListUI tableViewer;
private final String column;

public GroupNamingEditingSupport(SampleGroupAssignerListUI tableViewer, String column) {

super(tableViewer);
this.column = column;
if(SampleGroupAssignerLabelProvider.SELECT.equals(column)) {
this.cellEditor = new CheckboxCellEditor(tableViewer.getTable());
}
this.tableViewer = tableViewer;
}

@Override
protected CellEditor getCellEditor(Object element) {

return cellEditor;
}

@Override
protected boolean canEdit(Object element) {

return true;
}

@Override
protected Object getValue(Object element) {

if(element instanceof ISample sample) {
switch(column) {
case SampleGroupAssignerLabelProvider.SELECT:
return sample.isSelected();
}
}
return false;
}

@Override
protected void setValue(Object element, Object value) {

if(element instanceof ISample sample) {
switch(column) {
case SampleGroupAssignerLabelProvider.SELECT:
sample.setSelected((boolean)value);
break;
}
tableViewer.refresh();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lorenz Gerber - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.xxd.process.supplier.pca.ui.internal.provider;

import org.eclipse.chemclipse.model.statistics.ISample;
import org.eclipse.chemclipse.rcp.ui.icons.core.ApplicationImageFactory;
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImage;
import org.eclipse.chemclipse.rcp.ui.icons.core.IApplicationImageProvider;
import org.eclipse.chemclipse.support.ui.provider.AbstractChemClipseLabelProvider;
import org.eclipse.swt.graphics.Image;

public class SampleGroupAssignerLabelProvider extends AbstractChemClipseLabelProvider {

public static final String SAMPLE_NAME = "Sample Name";
public static final String SELECT = "Select";
public static final String GROUP_NAME = "Group Name";
public static final int INDEX_COLOR = 2;
//
public static String[] TITLES = {//
SAMPLE_NAME, //
SELECT, //
GROUP_NAME //
};
//
public static int[] BOUNDS = {//
300, //
30, //
100, //
};

@Override
public Image getColumnImage(Object element, int columnIndex) {

if(columnIndex == 0) {
return getImage(element);
} else if(columnIndex == 1) {
if(element instanceof ISample sample) {
if(sample.isSelected()) {
return ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_SELECTED, IApplicationImageProvider.SIZE_16x16);
} else {
return ApplicationImageFactory.getInstance().getImage(IApplicationImage.IMAGE_DESELECTED, IApplicationImageProvider.SIZE_16x16);
}
}
}
return null;
}

@Override
public String getColumnText(Object element, int columnIndex) {

String text = "";
if(element instanceof ISample sample) {
//
switch(columnIndex) {
case 0:
text = sample.getSampleName() != null ? sample.getSampleName() : "";
break;
case 1:
text = ""; // Checkbox
break;
case 2:
text = sample.getGroupName() != null ? sample.getGroupName() : "";
break;
}
}
return text;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lorenz Gerber - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.xxd.process.supplier.pca.ui.internal.wizards;

import java.util.List;

import org.eclipse.chemclipse.model.statistics.ISample;
import org.eclipse.chemclipse.model.statistics.IVariable;
import org.eclipse.chemclipse.xxd.process.supplier.pca.model.ISamplesPCA;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.Wizard;

public class GroupNamingWizard extends Wizard implements IWizard {

private GroupNamingWizardPage groupNamingWizardPage;
private ISamplesPCA<IVariable, ISample> samples;

public GroupNamingWizard(ISamplesPCA<IVariable, ISample> samples) {

this.groupNamingWizardPage = new GroupNamingWizardPage(samples);
this.samples = samples;
}

@Override
public void addPages() {

addPage(groupNamingWizardPage);
}

@Override
public boolean performFinish() {

List<ISample> groupSamples = this.groupNamingWizardPage.getGroupSamples();
for(int i = 0; i < groupSamples.size(); i++) {
samples.getSamples().get(i).setGroupName(groupSamples.get(i).getGroupName());
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*******************************************************************************
* Copyright (c) 2024 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Lorenz Gerber - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.xxd.process.supplier.pca.ui.internal.wizards;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.chemclipse.model.statistics.ISample;
import org.eclipse.chemclipse.model.statistics.IVariable;
import org.eclipse.chemclipse.xxd.process.supplier.pca.model.ISamplesPCA;
import org.eclipse.chemclipse.xxd.process.supplier.pca.model.Sample;
import org.eclipse.chemclipse.xxd.process.supplier.pca.ui.swt.SampleGroupAssignerListUI;
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.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

public class GroupNamingWizardPage extends AbstractAnalysisWizardPage {

private AtomicReference<SampleGroupAssignerListUI> sampleGroupAssignerListControl = new AtomicReference<>();
private ISamplesPCA<IVariable, ISample> samples;
private AtomicReference<Text> groupName = new AtomicReference<Text>();

public GroupNamingWizardPage(ISamplesPCA<IVariable, ISample> samples) {

super(GroupNamingWizardPage.class.getName());
setTitle("Group Naming Tool");
setDescription("Tool for quickly naming/creating/assigning Groups");
this.samples = samples;
}

@Override
public void createControl(Composite parent) {

Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, true));
createToolbar(composite);
createSampleGroupAssignerListUI(composite);
setControl(parent);
}

private void createSampleGroupAssignerListUI(Composite composite) {

SampleGroupAssignerListUI sampleGroupAssignerListUI = new SampleGroupAssignerListUI(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
Table table = sampleGroupAssignerListUI.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
sampleGroupAssignerListControl.set(sampleGroupAssignerListUI);
sampleGroupAssignerListUI.updateInput(extractSamples(samples.getSamples()));
}

private List<ISample> extractSamples(List<ISample> samples) {

List<ISample> groupNamingSamples = new ArrayList<ISample>();
for(ISample sample : samples) {
ISample groupNamingSample = new Sample(sample.getSampleName(), sample.getGroupName());
groupNamingSample.setSelected(false);
groupNamingSamples.add(groupNamingSample);
}
return groupNamingSamples;
}

private void createToolbar(Composite parent) {

Composite composite = new Composite(parent, SWT.NONE);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalAlignment = SWT.BEGINNING;
composite.setLayoutData(gridData);
composite.setLayout(new GridLayout(5, false));
//
createButtonAssign(composite);
createLabel(composite, "Group Name:");
createGroupNameEntry(composite);
createButtonZeroSelection(composite);
createButtonInverseSelection(composite);
}

private Label createLabel(Composite parent, String text) {

Label label = new Label(parent, SWT.NONE);
label.setText(text);
return label;
}

private Button createButtonAssign(Composite parent) {

Button button = new Button(parent, SWT.PUSH);
button.setToolTipText("Assign Groups to selected Samples.");
button.setText("Assign Groups");
button.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {

sampleGroupAssignerListControl.get().assignGroups(groupName.get().getText());
}
});
//
return button;
}

private void createGroupNameEntry(Composite parent) {

Text text = new Text(parent, SWT.NONE);
text.setToolTipText("Enter Groupname to be assigned to Samples");
GridData gridData = new GridData();
gridData.widthHint = 150;
text.setLayoutData(gridData);
groupName.set(text);
}

private Button createButtonZeroSelection(Composite parent) {

Button button = new Button(parent, SWT.PUSH);
button.setToolTipText("Unselect all.");
button.setText("Unselect");
button.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {

@SuppressWarnings("unchecked")
List<ISample> groupNamingSamples = (List<ISample>)sampleGroupAssignerListControl.get().getInput();
for(ISample sample : groupNamingSamples) {
sample.setSelected(false);
}
sampleGroupAssignerListControl.get().updateInput(groupNamingSamples);
}
});
//
return button;
}

private Button createButtonInverseSelection(Composite parent) {

Button button = new Button(parent, SWT.PUSH);
button.setToolTipText("Inverse Select Samples.");
button.setText("Inverse");
button.addSelectionListener(new SelectionAdapter() {

@Override
public void widgetSelected(SelectionEvent e) {

@SuppressWarnings("unchecked")
List<ISample> groupNamingSamples = (List<ISample>)sampleGroupAssignerListControl.get().getInput();
for(ISample sample : groupNamingSamples) {
if(sample.isSelected()) {
sample.setSelected(false);
} else {
sample.setSelected(true);
}
}
sampleGroupAssignerListControl.get().updateInput(groupNamingSamples);
}
});
//
return button;
}

@SuppressWarnings("unchecked")
public List<ISample> getGroupSamples() {

return (List<ISample>)sampleGroupAssignerListControl.get().getInput();
}
}
Loading