Skip to content

Commit

Permalink
Merge pull request #957 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
refactor code for the link to content limit info
  • Loading branch information
ashitsalesforce authored Jan 23, 2024
2 parents f2e1bad + cefc673 commit d716bd4
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Object convert(Class type, Object value) {
if (mimeType.equalsIgnoreCase("text/plain")
&& config != null
&& config.getBoolean(Config.LOAD_PRESERVE_WHITESPACE_IN_RICH_TEXT)
&& "ContentNote".equalsIgnoreCase(config.getString(Config.ENTITY))) {
&& AppUtil.isContentSObject(config.getString(Config.ENTITY))) {
// Preserve the formatting only if the content is of type plain text
// AND the flag to preserve whitespace characters in RichText fields is enabled
// AND the content is for ContentNote sobject.
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/com/salesforce/dataloader/ui/ContentLimitLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2015, salesforce.com, inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/


package com.salesforce.dataloader.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;

import com.salesforce.dataloader.config.Config;
import com.salesforce.dataloader.controller.Controller;
import com.salesforce.dataloader.util.AppUtil;

/**
*
*/
public class ContentLimitLink extends Link {

/**
* @param parent
* @param style
*/
private Controller controller;

public ContentLimitLink(Composite parent, int style, Controller controller) {
super(parent, style);
this.controller = controller;
this.setText(Labels.getString("UI.contentUploadLimit"));
this.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIUtils.openURL(e.text);
}
});

// based on https://www.informit.com/articles/article.aspx?p=354574&seqNum=3
this.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event e) {
setVisible();
}
});
}

public void setVisible() {
Config config = controller.getConfig();
String operation = config.getString(Config.OPERATION);
boolean isVisible = AppUtil.isContentSObject(
config.getString(Config.ENTITY))
&& operation != null
&& ("insert".equalsIgnoreCase(operation)
|| "update".equalsIgnoreCase(operation)
|| "upsert".equalsIgnoreCase(operation));
setVisible(isVisible);
}

// Based on answer at https://stackoverflow.com/questions/4264983/why-is-subclassing-not-allowed-for-many-of-the-swt-controls
@Override
protected void checkSubclass() {
// allow subclass
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
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.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;

import com.salesforce.dataloader.config.Config;
Expand All @@ -55,7 +52,7 @@ public class DataSelectionDialog extends BaseDialog {
private boolean success;
private Button ok;
private Label label;
private Link contentNoteLimitLink;
private ContentLimitLink contentNoteLimitLink;

/**
* InputDialog constructor
Expand Down Expand Up @@ -140,10 +137,7 @@ public void run() {
success = true;
ok.setEnabled(true);
String apiInfoStr = getController().getAPIInfo();
String contentNoteLimitsStr = "";
if ("ContentNote".equalsIgnoreCase(sObjectName)) {
contentNoteLimitsStr = "\n\n<a href=\"https://help.salesforce.com/s/articleView?id=sf.content_file_size_limits.htm&type=5\">ContentNote limits</a>";
}

// Set the description
label.setText(Labels.getFormattedString(
"DataSelectionDialog.initSuccess", String.valueOf(totalRows))
Expand All @@ -159,8 +153,7 @@ public void run() {
+ apiInfoStr
); //$NON-NLS-1$

contentNoteLimitLink.setText(contentNoteLimitsStr);
label.getParent().pack();
label.getParent().pack();
}

});
Expand Down Expand Up @@ -193,18 +186,11 @@ protected void createContents(final Shell shell) {
labelData.widthHint = 400;
label.setLayoutData(labelData);

contentNoteLimitLink = new Link(shell, SWT.WRAP);
contentNoteLimitLink.setText("");
contentNoteLimitLink = new ContentLimitLink(shell, SWT.WRAP, getController());
GridData linkData = new GridData();
linkData.horizontalSpan = 2;
linkData.widthHint = 400;
contentNoteLimitLink.setLayoutData(linkData);
contentNoteLimitLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
UIUtils.openURL(e.text);
}
});

//the bottom separator
Label labelSeparatorBottom = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/salesforce/dataloader/ui/FinishPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
public class FinishPage extends LoadPage {

private DirectoryFieldEditor dirFE;
private ContentLimitLink contentNoteLimitLink;

public FinishPage(Controller controller) {
this("FinishPage", controller); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -88,6 +89,9 @@ public void modifyText(ModifyEvent arg0) {
}

});

contentNoteLimitLink = new ContentLimitLink(comp, SWT.WRAP, getController());

hook_createControl(comp);
setControl(comp);
setupPage();
Expand Down Expand Up @@ -122,11 +126,13 @@ public void run() {
});
return false;
}

setPageComplete();
IWizardContainer wizardContainer = this.getContainer();
if (wizardContainer != null) {
wizardContainer.updateButtons();
}
contentNoteLimitLink.setVisible();
if (!controller.saveConfig()) return false;
return true;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/salesforce/dataloader/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public enum APP_RUN_MODE {
private static APP_RUN_MODE appRunMode = APP_RUN_MODE.UI;
private static Logger logger = null;
private static String latestDownloadableDataLoaderVersion;
private static final ArrayList<String> CONTENT_SOBJECT_LIST = new ArrayList<String>();

static {
Properties versionProps = new Properties();
Expand All @@ -121,7 +122,7 @@ public enum APP_RUN_MODE {
String[] versionParts = DATALOADER_VERSION.split("\\.");
DATALOADER_SHORT_VERSION=versionParts[0];
MIN_JAVA_VERSION=versionProps.getProperty("java.min.version");

CONTENT_SOBJECT_LIST.add("ContentNote".toLowerCase());
}

public static String[] initializeAppConfig(String[] args) throws FactoryConfigurationError, IOException, ConfigInitializationException {
Expand Down Expand Up @@ -261,10 +262,14 @@ public static void setUseGMTForDateFieldValue(boolean val) {
useGMTForDateFieldValue = val;
}

public static boolean isContentSObject(String sObjectName) {
return CONTENT_SOBJECT_LIST.contains(sObjectName.toLowerCase());
}
private static boolean useGMTForDateFieldValue;
public static boolean isUseGMTForDateFieldValue() {
return useGMTForDateFieldValue;
}

private static String configurationsDir = null;
public static synchronized String getConfigurationsDir() {
if (configurationsDir == null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/labels.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ UI.warning=Warning
UI.error=Error
UI.message=Info
UI.fileAlreadyExists=The file you have selected already exists. Would you like to replace the existing file?
UI.contentUploadLimit=Make sure that the Content files to be uploaded are within <a href="https://help.salesforce.com/s/articleView?id=sf.content_file_size_limits.htm">specified limits</a>

DataSelectionDialog.title=Data Selection
DataSelectionDialog.titleError=Data Selection Error
Expand Down

0 comments on commit d716bd4

Please sign in to comment.