public code v1
This commit is contained in:
+171
@@ -0,0 +1,171 @@
|
||||
package flintstones.entity.domain.ui.dialog;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
||||
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewerColumn;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
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.Control;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import flintstones.entity.domain.DomainMockup;
|
||||
import flintstones.entity.domain.ui.dialog.messages.Messages;
|
||||
import flintstones.entity.domain.ui.provider.DomainDomainMockupContentProvider;
|
||||
import flintstones.entity.domain.ui.provider.DomainMockupLabelProvider;
|
||||
import flintstones.model.domain.service.IDomainService;
|
||||
|
||||
/**
|
||||
* @author Sinbad2
|
||||
*
|
||||
*/
|
||||
public class AddDomainDialog extends Dialog {
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
private static final int DIALOG_SIZE_Y = 400;
|
||||
|
||||
private static final int DIALOG_SIZE_X = 450;
|
||||
|
||||
@Inject
|
||||
IDomainService domainService;
|
||||
|
||||
@Inject
|
||||
IEclipseContext context;
|
||||
|
||||
|
||||
private Button okButton;
|
||||
|
||||
private String selectedDomainExtension;
|
||||
|
||||
/**
|
||||
* @param parentShell The parent shell
|
||||
*/
|
||||
@Inject
|
||||
public AddDomainDialog(Shell parentShell) {
|
||||
super(parentShell);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite container = (Composite) super.createDialogArea(parent);
|
||||
|
||||
GridLayout layout = new GridLayout(1, false);
|
||||
|
||||
layout.verticalSpacing = 2;
|
||||
layout.marginWidth = 0;
|
||||
layout.marginHeight = 0;
|
||||
layout.horizontalSpacing = 0;
|
||||
parent.setLayout(layout);
|
||||
|
||||
this.addTreeView(container);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
private void addTreeView(Composite container) {
|
||||
|
||||
DomainMockupLabelProvider delp = ContextInjectionFactory.make(DomainMockupLabelProvider.class, this.context);
|
||||
DomainDomainMockupContentProvider dccp = ContextInjectionFactory.make(DomainDomainMockupContentProvider.class, context);
|
||||
|
||||
final TreeViewer tv = new TreeViewer(container);
|
||||
tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
tv.setContentProvider(dccp);
|
||||
|
||||
TreeViewerColumn mainColumn = new TreeViewerColumn(tv, SWT.NONE);
|
||||
mainColumn.getColumn().setText("Domains");
|
||||
mainColumn.getColumn().setWidth(300);
|
||||
mainColumn.setLabelProvider(new DelegatingStyledCellLabelProvider(delp));
|
||||
|
||||
tv.getTree().setHeaderVisible(true);
|
||||
tv.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
|
||||
|
||||
DomainMockup[] domains = domainService.getMockupDomains();
|
||||
|
||||
tv.setInput(domains);
|
||||
tv.addSelectionChangedListener(this.treeviewOnclick());
|
||||
}
|
||||
|
||||
private ISelectionChangedListener treeviewOnclick() {
|
||||
return event -> {
|
||||
ISelection selection = event.getSelection();
|
||||
Iterator<?> selectedElements = ((IStructuredSelection) selection).iterator();
|
||||
|
||||
if (!selectedElements.hasNext())
|
||||
return;
|
||||
|
||||
Object next = selectedElements.next();
|
||||
|
||||
DomainMockup de = (DomainMockup) next;
|
||||
boolean isDomain = de.getId() != null;
|
||||
|
||||
AddDomainDialog.this.okButton.setEnabled(isDomain);
|
||||
|
||||
if(isDomain)
|
||||
AddDomainDialog.this.setSelectedDomainExtension(de.getId());
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// overriding this methods allows you to set the
|
||||
// title of the custom dialog
|
||||
@Override
|
||||
protected void configureShell(Shell newShell) {
|
||||
super.configureShell(newShell);
|
||||
newShell.setText(this.messages.title_add_domain_dialog);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getInitialSize() {
|
||||
return new Point(AddDomainDialog.DIALOG_SIZE_X, AddDomainDialog.DIALOG_SIZE_Y);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void okPressed() {
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createButtonsForButtonBar(Composite parent) {
|
||||
this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
|
||||
this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
|
||||
|
||||
this.okButton = this.getButton(IDialogConstants.OK_ID);
|
||||
this.okButton.setEnabled(false);
|
||||
// UiService.reLayoutShell(this.getShell());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the selectedDomainExtension
|
||||
*/
|
||||
public String getSelectedDomainExtension() {
|
||||
return this.selectedDomainExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param selectedDomainExtension the selectedDomainExtension to set
|
||||
*/
|
||||
public void setSelectedDomainExtension(String selectedDomainExtension) {
|
||||
this.selectedDomainExtension = selectedDomainExtension;
|
||||
}
|
||||
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
package flintstones.entity.domain.ui.dialog;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import flintstones.entity.domain.Domain;
|
||||
import flintstones.entity.domain.ui.dialog.messages.Messages;
|
||||
import flintstones.helper.ui.components.ValidatedField;
|
||||
import flintstones.model.domain.service.IDomainService;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
public abstract class DomainDialog extends Dialog {
|
||||
|
||||
private Domain domain;
|
||||
private Button okButton;
|
||||
|
||||
private String oldName = "";
|
||||
private String newName = "";
|
||||
|
||||
private ValidatedField nameField;
|
||||
private boolean lastCheck = false;
|
||||
|
||||
@Inject
|
||||
IDomainService domainService;
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
protected DomainDialog() {
|
||||
super(Display.getCurrent().getActiveShell());
|
||||
}
|
||||
|
||||
public Domain getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return newName;
|
||||
}
|
||||
|
||||
public void setDomainTop(Domain base) {
|
||||
|
||||
domain = base;
|
||||
oldName = base.getName();
|
||||
newName = base.getName();
|
||||
|
||||
this.create();
|
||||
beforeUI();
|
||||
}
|
||||
|
||||
public void setSaveEnabled(boolean enabled) {
|
||||
lastCheck = enabled;
|
||||
refresheEnabled();
|
||||
}
|
||||
|
||||
protected void addNameField(Composite container) {
|
||||
|
||||
UiService.setMargin(container, 0);
|
||||
|
||||
nameField = new ValidatedField(container, messages.Domain_name_label, getDomain().getName());
|
||||
nameField.getInput().addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
newName = nameField.getText();
|
||||
checkDomainName();
|
||||
refresheEnabled();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
protected abstract void beforeUI();
|
||||
|
||||
private void refresheEnabled() {
|
||||
if (okButton != null)
|
||||
okButton.setEnabled(lastCheck && checkDomainName());
|
||||
|
||||
}
|
||||
|
||||
private boolean checkDomainName() {
|
||||
|
||||
boolean isValid = isValidName(newName);
|
||||
|
||||
// 1. Domain name should not be not empty
|
||||
if (!isValid && (newName == null || newName.equals(""))) { //$NON-NLS-1$
|
||||
nameField.setError(messages.Empty_domain);
|
||||
} else if(!isValid) {
|
||||
nameField.setError(messages.Duplicated_name);
|
||||
} else {
|
||||
nameField.setError("");
|
||||
}
|
||||
|
||||
return isValid;
|
||||
|
||||
}
|
||||
|
||||
private boolean isValidName(String name) {
|
||||
|
||||
if(name == null)
|
||||
return false;
|
||||
|
||||
if(name.equals(""))
|
||||
return false;
|
||||
|
||||
if(name.equals(oldName))
|
||||
return true;
|
||||
|
||||
return domainService.getByName(name) == null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createButtonsForButtonBar(Composite parent) {
|
||||
this.okButton = this.createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
|
||||
this.okButton.setEnabled(false);
|
||||
this.createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
|
||||
this.okButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
domain.setName(newName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package flintstones.entity.domain.ui.dialog;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Translation;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
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.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import flintstones.entity.domain.ui.dialog.messages.Messages;
|
||||
import flintstones.helper.ui.components.WLabel;
|
||||
import flintstones.model.ui.service.UiService;
|
||||
|
||||
/**
|
||||
* The Class SelectNewDomainDialog.
|
||||
*/
|
||||
public class SelectBetweenMultipleDomainsDialog extends Dialog {
|
||||
|
||||
|
||||
@Inject
|
||||
@Translation
|
||||
private Messages messages;
|
||||
|
||||
/** The selected id. */
|
||||
private String selected;
|
||||
|
||||
String[] descriptions;
|
||||
|
||||
/**
|
||||
* Instantiates a new select new domain dialog.
|
||||
*/
|
||||
public SelectBetweenMultipleDomainsDialog() {
|
||||
super(Display.getCurrent().getActiveShell());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.
|
||||
* Composite)
|
||||
*/
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite container = (Composite) super.createDialogArea(parent);
|
||||
|
||||
WLabel label = new WLabel(container);
|
||||
UiService.setFont(label, UiService.FONT_SECTION_TITLE);
|
||||
label.setText(this.messages.title_select_new_domain_dialog);
|
||||
|
||||
for (String description : descriptions) {
|
||||
Button button = new Button(container, SWT.RADIO);
|
||||
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
|
||||
|
||||
button.setText(description);
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
String selectedDescription = ((Button) e.getSource()).getText();
|
||||
selected = selectedDescription;
|
||||
};
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
||||
*/
|
||||
@Override
|
||||
protected void configureShell(Shell newShell) {
|
||||
super.configureShell(newShell);
|
||||
newShell.setText(this.messages.title_select_new_domain_dialog);
|
||||
}
|
||||
|
||||
public void setDescriptions(String[] descriptions) {
|
||||
this.descriptions = descriptions;
|
||||
}
|
||||
|
||||
public String getSelected() { return selected; }
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// This file has been auto-generated
|
||||
package flintstones.entity.domain.ui.dialog.messages;
|
||||
|
||||
import org.eclipse.e4.core.services.nls.Message;
|
||||
|
||||
@Message
|
||||
@SuppressWarnings("javadoc")
|
||||
public class Messages {
|
||||
|
||||
public String title_add_domain_dialog;
|
||||
public String title_select_new_domain_dialog;
|
||||
|
||||
public String Domain_name_label;
|
||||
public String Empty_domain;
|
||||
public String Duplicated_name;
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
title_add_domain_dialog=Choose domain type
|
||||
title_select_new_domain_dialog=Choose the domain
|
||||
Domain_name_label=Domain name
|
||||
Empty_domain=The domain name should not be empty
|
||||
Duplicated_name=The selected name is being used by another domain
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
title_add_domain_dialog=Elija el tipo de dominio
|
||||
title_select_new_domain_dialog=Elija el dominio
|
||||
Domain_name_label=Nombre del dominio
|
||||
Empty_domain=El nombre del dominio no debe estar vacío
|
||||
Duplicated_name=El nombre del dominio ya existe
|
||||
Reference in New Issue
Block a user