-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 548113 provide ability to create user from issue license wizard
Add RootClassifierWizard Signed-off-by: Alexander Fedorov <alexander.fedorov@arsysop.ru>
- Loading branch information
1 parent
8dfa0a1
commit f6a4620
Showing
7 changed files
with
173 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...orkbench/src/org/eclipse/passage/loc/internal/workbench/wizards/RootClassifierWizard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.eclipse.passage.loc.internal.workbench.wizards; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.emf.ecore.resource.ResourceSet; | ||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; | ||
import org.eclipse.emf.edit.domain.IEditingDomainProvider; | ||
import org.eclipse.passage.lic.base.LicensingResults; | ||
import org.eclipse.passage.lic.emf.ecore.EditingDomainRegistry; | ||
import org.eclipse.passage.lic.emf.edit.ClassifierInitializer; | ||
import org.eclipse.passage.lic.jface.dialogs.LicensingResultDialogs; | ||
import org.eclipse.passage.loc.internal.workbench.ClassifierMetadata; | ||
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; | ||
import org.eclipse.passage.loc.workbench.LocWokbench; | ||
|
||
/** | ||
* Creates new root licensing object. Can be asked for a reference to a created | ||
* instance. | ||
* | ||
* @since 0.6 | ||
* | ||
*/ | ||
public final class RootClassifierWizard extends BaseClassifierWizard<RootClassifierWizardPage> { | ||
|
||
private final EditingDomainRegistry<?> domainRegistry; | ||
|
||
public RootClassifierWizard(ClassifierMetadata metadata, ClassifierInitializer initializer, | ||
EditingDomainRegistry<?> registry) { | ||
super(metadata, initializer); | ||
this.domainRegistry = registry; | ||
} | ||
|
||
@Override | ||
protected RootClassifierWizardPage createNewClassifierPage(ClassifierMetadata metadata, | ||
ClassifierInitializer initializer) { | ||
return new RootClassifierWizardPage(metadata, initializer, domainRegistry.getFileExtension()); | ||
} | ||
|
||
@Override | ||
public boolean performFinish() { | ||
try { | ||
getContainer().run(false, false, m -> store(newClassifierPage.path(), newClassifierPage.candidate())); | ||
return true; | ||
} catch (Exception exception) { | ||
process(exception); | ||
return false; | ||
} | ||
} | ||
|
||
protected void store(String path, EObject candidate) { | ||
URI fileURI = URI.createFileURI(path); | ||
Resource resource = resourceSet().createResource(fileURI); | ||
resource.getContents().add(candidate); | ||
LocWokbench.save(resource); | ||
domainRegistry.registerSource(fileURI.toFileString()); | ||
} | ||
|
||
protected ResourceSet resourceSet() { | ||
if (domainRegistry instanceof IEditingDomainProvider) { | ||
IEditingDomainProvider edProvider = (IEditingDomainProvider) domainRegistry; | ||
return edProvider.getEditingDomain().getResourceSet(); | ||
} | ||
return new ResourceSetImpl(); | ||
} | ||
|
||
protected void process(Exception exception) { | ||
LicensingResultDialogs.openMessageDialog(getShell(), WorkbenchMessages.RootClassifierWizard_title_e_create, // | ||
LicensingResults.createError(WorkbenchMessages.RootClassifierWizard_message_e_create, | ||
getClass().getName(), exception)); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...ench/src/org/eclipse/passage/loc/internal/workbench/wizards/RootClassifierWizardPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.eclipse.passage.loc.internal.workbench.wizards; | ||
|
||
import java.io.File; | ||
|
||
import org.eclipse.passage.lic.emf.edit.ClassifierInitializer; | ||
import org.eclipse.passage.loc.internal.workbench.ClassifierMetadata; | ||
import org.eclipse.passage.loc.internal.workbench.i18n.WorkbenchMessages; | ||
import org.eclipse.passage.loc.workbench.LocWokbench; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.events.SelectionListener; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.widgets.Button; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Text; | ||
|
||
/** | ||
* Provides UI to to fulfill the field values for a root classifier to be | ||
* created, including path to store the new resource. | ||
* | ||
* @since 0.6 | ||
* | ||
* @see BaseClassifierWizardPage | ||
* | ||
*/ | ||
public final class RootClassifierWizardPage extends BaseClassifierWizardPage { | ||
|
||
private final String extension; | ||
|
||
protected Text textPath; | ||
private Button buttonPath; | ||
|
||
protected RootClassifierWizardPage(ClassifierMetadata metadata, ClassifierInitializer initializer, | ||
String extension) { | ||
super(RootClassifierWizardPage.class.getSimpleName(), metadata, initializer); | ||
this.extension = extension; | ||
} | ||
|
||
@Override | ||
protected void createFieldControls(Composite composite) { | ||
super.createFieldControls(composite); | ||
textPath = new Text(composite, SWT.BORDER); | ||
{ | ||
GridData data = new GridData(); | ||
data.horizontalAlignment = GridData.FILL; | ||
data.grabExcessHorizontalSpace = true; | ||
data.horizontalSpan = 1; | ||
textPath.setLayoutData(data); | ||
} | ||
buttonPath = new Button(composite, SWT.PUSH); | ||
buttonPath.setText(WorkbenchMessages.CreateFileWizardPage_button_browse); | ||
textPath.addModifyListener(validator); | ||
buttonPath.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> selectPath())); | ||
} | ||
|
||
protected void selectPath() { | ||
String selected = LocWokbench.selectSavePath(getShell(), extension); | ||
if (selected != null) { | ||
textPath.setText(selected); | ||
} | ||
} | ||
|
||
@Override | ||
protected void initControls(ClassifierInitializer initializer) { | ||
super.initControls(initializer); | ||
String basePath = basePath(); | ||
String fileName = initializer.newFileName(); | ||
String resourceURI = basePath + File.separator + fileName + '.' + extension; | ||
textPath.setText(resourceURI); | ||
} | ||
|
||
protected String basePath() { | ||
return System.getProperty("user.home"); //$NON-NLS-1$ | ||
} | ||
|
||
protected String path() { | ||
String text = textPath.getText(); | ||
if (!text.endsWith('.' + extension)) { | ||
text = text + '.' + extension; | ||
} | ||
return text; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters