📄 extlibrarymodelwizard.java
字号:
* <!-- end-user-doc -->
* @generated
*/
protected boolean validatePage()
{
if (super.validatePage())
{
// Make sure the file ends in ".extlibrary".
//
String requiredExt = EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryEditorFilenameExtension"); //$NON-NLS-1$
String enteredExt = new Path(getFileName()).getFileExtension();
if (enteredExt == null || !enteredExt.equals(requiredExt))
{
setErrorMessage(EXTLibraryEditorPlugin.INSTANCE.getString("_WARN_FilenameExtension", new Object [] { requiredExt })); //$NON-NLS-1$
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IFile getModelFile()
{
return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName()));
}
}
/**
* This is the page where the type of object to create is selected.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public class EXTLibraryModelWizardInitialObjectCreationPage extends WizardPage
{
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Combo initialObjectField;
/**
* @generated
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*/
protected List encodings;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Combo encodingField;
/**
* Pass in the selection.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public EXTLibraryModelWizardInitialObjectCreationPage(String pageId)
{
super(pageId);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void createControl(Composite parent)
{
Composite composite = new Composite(parent, SWT.NONE);
{
GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.verticalSpacing = 12;
composite.setLayout(layout);
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.grabExcessVerticalSpace = true;
data.horizontalAlignment = GridData.FILL;
composite.setLayoutData(data);
}
Label containerLabel = new Label(composite, SWT.LEFT);
{
containerLabel.setText(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_ModelObject")); //$NON-NLS-1$
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
containerLabel.setLayoutData(data);
}
initialObjectField = new Combo(composite, SWT.BORDER);
{
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
initialObjectField.setLayoutData(data);
}
for (Iterator i = getInitialObjectNames().iterator(); i.hasNext(); )
{
initialObjectField.add(getLabel((String)i.next()));
}
if (initialObjectField.getItemCount() == 1)
{
initialObjectField.select(0);
}
initialObjectField.addModifyListener(validator);
Label encodingLabel = new Label(composite, SWT.LEFT);
{
encodingLabel.setText(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_XMLEncoding")); //$NON-NLS-1$
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
encodingLabel.setLayoutData(data);
}
encodingField = new Combo(composite, SWT.BORDER);
{
GridData data = new GridData();
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
encodingField.setLayoutData(data);
}
for (Iterator i = getEncodings().iterator(); i.hasNext(); )
{
encodingField.add((String)i.next());
}
encodingField.select(0);
encodingField.addModifyListener(validator);
setPageComplete(validatePage());
setControl(composite);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ModifyListener validator =
new ModifyListener()
{
public void modifyText(ModifyEvent e)
{
setPageComplete(validatePage());
}
};
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected boolean validatePage()
{
return getInitialObjectName() != null && getEncodings().contains(encodingField.getText());
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setVisible(boolean visible)
{
super.setVisible(visible);
if (visible)
{
if (initialObjectField.getItemCount() == 1)
{
initialObjectField.clearSelection();
encodingField.setFocus();
}
else
{
encodingField.clearSelection();
initialObjectField.setFocus();
}
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getInitialObjectName()
{
String label = initialObjectField.getText();
for (Iterator i = getInitialObjectNames().iterator(); i.hasNext(); )
{
String name = (String)i.next();
if (getLabel(name).equals(label))
{
return name;
}
}
return null;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public String getEncoding()
{
return encodingField.getText();
}
/**
* Returns the label for the specified type name.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected String getLabel(String typeName)
{
try
{
return EXTLibraryEditPlugin.INSTANCE.getString("_UI_" + typeName + "_type"); //$NON-NLS-1$ //$NON-NLS-2$
}
catch(MissingResourceException mre)
{
EXTLibraryEditorPlugin.INSTANCE.log(mre);
}
return typeName;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected Collection getEncodings()
{
if (encodings == null)
{
encodings = new ArrayList();
for (StringTokenizer stringTokenizer = new StringTokenizer(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_XMLEncodingChoices")); stringTokenizer.hasMoreTokens(); ) //$NON-NLS-1$
{
encodings.add(stringTokenizer.nextToken());
}
}
return encodings;
}
}
/**
* The framework calls this to create the contents of the wizard.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void addPages()
{
// Create a page, set the title, and the initial model file name.
//
newFileCreationPage = new EXTLibraryModelWizardNewFileCreationPage("Whatever", selection); //$NON-NLS-1$
newFileCreationPage.setTitle(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryModelWizard_label")); //$NON-NLS-1$
newFileCreationPage.setDescription(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryModelWizard_description")); //$NON-NLS-1$
newFileCreationPage.setFileName(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryEditorFilenameDefaultBase") + "." + EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryEditorFilenameExtension")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
addPage(newFileCreationPage);
// Try and get the resource selection to determine a current directory for the file dialog.
//
if (selection != null && !selection.isEmpty())
{
// Get the resource...
//
Object selectedElement = selection.iterator().next();
if (selectedElement instanceof IResource)
{
// Get the resource parent, if its a file.
//
IResource selectedResource = (IResource)selectedElement;
if (selectedResource.getType() == IResource.FILE)
{
selectedResource = selectedResource.getParent();
}
// This gives us a directory...
//
if (selectedResource instanceof IFolder || selectedResource instanceof IProject)
{
// Set this for the container.
//
newFileCreationPage.setContainerFullPath(selectedResource.getFullPath());
// Make up a unique new name here.
//
String defaultModelBaseFilename = EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryEditorFilenameDefaultBase"); //$NON-NLS-1$
String defaultModelFilenameExtension = EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryEditorFilenameExtension"); //$NON-NLS-1$
String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; //$NON-NLS-1$
for (int i = 1; ((IContainer)selectedResource).findMember(modelFilename) != null; ++i)
{
modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; //$NON-NLS-1$
}
newFileCreationPage.setFileName(modelFilename);
}
}
}
initialObjectCreationPage = new EXTLibraryModelWizardInitialObjectCreationPage("Whatever2"); //$NON-NLS-1$
initialObjectCreationPage.setTitle(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_EXTLibraryModelWizard_label")); //$NON-NLS-1$
initialObjectCreationPage.setDescription(EXTLibraryEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description")); //$NON-NLS-1$
addPage(initialObjectCreationPage);
}
/**
* Get the file from the page.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public IFile getModelFile()
{
return newFileCreationPage.getModelFile();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -